Browse Source

コメント取得追加

main
みてるぞ 1 week ago
parent
commit
f44637d274
1 changed files with 58 additions and 0 deletions
  1. +58
    -0
      get_comments_by_video_code.py

+ 58
- 0
get_comments_by_video_code.py View File

@@ -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])

Loading…
Cancel
Save