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

66 lines
1.6 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. 'user': row.user.code if row.user else None,
  23. 'title': row.title,
  24. 'description': row.description,
  25. 'tags': [],
  26. 'uploaded_at': row.uploaded_at,
  27. 'deleted_at': deleted_at }
  28. for video_tag in row.video_tags:
  29. if video_tag.untagged_at is None:
  30. video['tags'].append (video_tag.tag.name)
  31. videos.append(video)
  32. print (json.dumps (videos, default = str))
  33. class DbConfig (TypedDict):
  34. driver: str
  35. host: str
  36. database: str
  37. user: str
  38. password: str
  39. prefix: str
  40. class VideoDict (TypedDict):
  41. id: int
  42. code: str
  43. user: str | None
  44. title: str
  45. description: str
  46. tags: list[str]
  47. uploaded_at: datetime
  48. deleted_at: date | None
  49. if __name__ == '__main__':
  50. main ()