ぼざろクリーチャーシリーズ 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.
 
 
 

59 lines
1.4 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 os
  9. import sys
  10. from datetime import date, datetime
  11. from typing import TypedDict, cast
  12. from eloquent import DatabaseManager, Model
  13. from db.config import DB
  14. from db.models import Video
  15. DB
  16. def main (
  17. video_code: str,
  18. ) -> None:
  19. video = Video.where ('code', video_code).first ()
  20. if video:
  21. comments: list[CommentDict] = []
  22. for row in video.comments:
  23. comment: CommentDict = {
  24. 'id': row.id,
  25. 'video_id': row.video_id,
  26. 'comment_no': row.comment_no,
  27. 'user_id': row.user_id,
  28. 'content': row.content,
  29. 'posted_at': row.posted_at,
  30. 'nico_count': row.nico_count,
  31. 'vpos_ms': row.vpos_ms }
  32. comments.append (comment)
  33. print (json.dumps (comments, default = str))
  34. else:
  35. print ('[]')
  36. class CommentDict (TypedDict):
  37. id: int
  38. video_id: int
  39. comment_no: int
  40. user_id: int
  41. content: str
  42. posted_at: datetime
  43. nico_count: int
  44. vpos_ms: int
  45. if __name__ == '__main__':
  46. main (sys.argv[1])