# pylint: disable = missing-class-docstring # pylint: disable = missing-function-docstring """ 全動画の情報を取得し,JSON 形式で出力する. """ from __future__ import annotations import json import os from datetime import date, datetime from typing import TypedDict from eloquent import DatabaseManager, Model from db.config import DB from db.models import Video DB def main ( ) -> None: videos: list[VideoDict] = [] for row in Video.all (): deleted_at = row.deleted_at.date () if row.deleted_at else None video: VideoDict = { 'id': row.id, 'code': row.code, 'title': row.title, 'description': row.description, 'tags': [], 'uploaded_at': row.uploaded_at, 'deleted_at': deleted_at } for video_tag in row.video_tags: if video_tag.untagged_at is None: video['tags'].append (video_tag.tag.name) videos.append(video) print (json.dumps (videos, default = str)) class DbConfig (TypedDict): driver: str host: str database: str user: str password: str prefix: str class VideoDict (TypedDict): id: int code: str title: str description: str tags: list[str] uploaded_at: datetime deleted_at: date | None if __name__ == '__main__': main ()