みてるぞ 2 weeks ago
parent
commit
c9bd6fdfa7
1 changed files with 68 additions and 0 deletions
  1. +68
    -0
      get_videos.py

+ 68
- 0
get_videos.py View File

@@ -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 ()

Loading…
Cancel
Save