# pylint: disable = missing-class-docstring # pylint: disable = missing-function-docstring """ 動画コードからコメントのリストを取得し,JSON 形式で出力する. """ from __future__ import annotations import json import sys from datetime import datetime from typing import TypedDict 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])