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

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