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

64 lines
1.5 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. from datetime import date, datetime
  10. from typing import TypedDict
  11. from eloquent import DatabaseManager, Model
  12. from db.config import DB
  13. from db.models import Video
  14. DB
  15. def main (
  16. ) -> None:
  17. videos: list[VideoDict] = []
  18. for row in Video.all ():
  19. deleted_at = row.deleted_at.date () if row.deleted_at else None
  20. video: VideoDict = { 'id': row.id,
  21. 'code': row.code,
  22. 'title': row.title,
  23. 'description': row.description,
  24. 'tags': [],
  25. 'uploaded_at': row.uploaded_at,
  26. 'deleted_at': deleted_at }
  27. for video_tag in row.video_tags:
  28. if video_tag.untagged_at is None:
  29. video['tags'].append (video_tag.tag.name)
  30. videos.append(video)
  31. print (json.dumps (videos, default = str))
  32. class DbConfig (TypedDict):
  33. driver: str
  34. host: str
  35. database: str
  36. user: str
  37. password: str
  38. prefix: str
  39. class VideoDict (TypedDict):
  40. id: int
  41. code: str
  42. title: str
  43. description: str
  44. tags: list[str]
  45. uploaded_at: datetime
  46. deleted_at: date | None
  47. if __name__ == '__main__':
  48. main ()