From f44637d274c968bb942a7f9097ea7972f809643a Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sun, 26 Oct 2025 05:07:07 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E5=8F=96?= =?UTF-8?q?=E5=BE=97=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- get_comments_by_video_code.py | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 get_comments_by_video_code.py diff --git a/get_comments_by_video_code.py b/get_comments_by_video_code.py new file mode 100644 index 0000000..698e541 --- /dev/null +++ b/get_comments_by_video_code.py @@ -0,0 +1,58 @@ +# pylint: disable = missing-class-docstring +# pylint: disable = missing-function-docstring + +""" +動画コードからコメントのリストを取得し,JSON 形式で出力する. +""" + +from __future__ import annotations + +import json +import os +import sys +from datetime import date, datetime +from typing import TypedDict, cast + +from eloquent import DatabaseManager, Model + +from db.config import DB +from db.models import Video + +DB + + +def main ( + video_code: str, +) -> None: + video = Video.where ('code', video_code).first () + if video: + comments: list[CommentDict] = [] + for row in video.comments: + comment: CommentDict = { + 'id': row.id, + 'video_id': row.video_id, + 'comment_no': row.comment_no, + 'user_id': row.user_id, + 'content': row.content, + 'posted_at': row.posted_at, + 'nico_count': row.nico_count, + 'vpos_ms': row.vpos_ms } + comments.append (comment) + print (json.dumps (comments, default = str)) + else: + print ('[]') + + +class CommentDict (TypedDict): + id: int + video_id: int + comment_no: int + user_id: int + content: str + posted_at: datetime + nico_count: int + vpos_ms: int + + +if __name__ == '__main__': + main (sys.argv[1])