ぼざろクリーチャーシリーズ DB 兼 API(自分用)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

56 lines
1.3 KiB

  1. # pylint: disable = missing-class-docstring
  2. # pylint: disable = missing-function-docstring
  3. """
  4. 動画コードからコメントのリストを取得し,JSON 形式で出力する.
  5. """
  6. from __future__ import annotations
  7. import json
  8. import sys
  9. from datetime import datetime
  10. from typing import TypedDict
  11. from db.config import DB
  12. from db.models import Video
  13. DB
  14. def main (
  15. video_code: str,
  16. ) -> None:
  17. video = Video.where ('code', video_code).first ()
  18. if video:
  19. comments: list[CommentDict] = []
  20. for row in video.comments:
  21. comment: CommentDict = {
  22. 'id': row.id,
  23. 'video_id': row.video_id,
  24. 'comment_no': row.comment_no,
  25. 'user_id': row.user_id,
  26. 'content': row.content,
  27. 'posted_at': row.posted_at,
  28. 'nico_count': row.nico_count,
  29. 'vpos_ms': row.vpos_ms }
  30. comments.append (comment)
  31. print (json.dumps (comments, default = str))
  32. else:
  33. print ('[]')
  34. class CommentDict (TypedDict):
  35. id: int
  36. video_id: int
  37. comment_no: int
  38. user_id: int
  39. content: str
  40. posted_at: datetime
  41. nico_count: int
  42. vpos_ms: int
  43. if __name__ == '__main__':
  44. main (sys.argv[1])