このコミットが含まれているのは:
2025-07-01 23:39:57 +09:00
コミット c9bd6fdfa7
+68
ファイルの表示
@@ -0,0 +1,68 @@
# 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.models import Video
def main (
) -> None:
config: dict[str, DbConfig] = { 'mysql': { 'driver': 'mysql',
'host': 'localhost',
'database': 'nizika_nico',
'user': os.environ['MYSQL_USER'],
'password': os.environ['MYSQL_PASS'],
'prefix': '' } }
db = DatabaseManager (config)
Model.set_connection_resolver (db)
videos: list[VideoDict] = []
for row in Video.all ():
video: VideoDict = { 'id': row.id,
'code': row.code,
'title': row.title,
'description': row.description,
'tags': [],
'uploaded_at': row.uploaded_at,
'deleted_at': row.deleted_at.date () }
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))
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 ()