diff --git a/update_db.py b/update_db.py index 62f2dbe..036f12f 100644 --- a/update_db.py +++ b/update_db.py @@ -18,7 +18,7 @@ import requests # TODO: “何もしなぃ” を意味する None と区別可能にするため,NULL クラスを別途用意すること DbNull = None -DbNullType = None +DbNullType = type (None) class VideoSearchParam (TypedDict): @@ -33,7 +33,7 @@ class VideoSearchParam (TypedDict): class VideoResult (TypedDict): contentId: str title: str - tags: list[str] + tags: str description: str viewCounter: int startTime: str @@ -91,6 +91,7 @@ def update_tables ( ) -> None: video_ids: list[int] = [] for datum in api_data: + tag_names = datum['tags'].split () video = VideoDto (code = datum['contentId'], title = datum['title'], description = datum['description'], @@ -107,12 +108,12 @@ def update_tables ( for vt in video_tags: tag = tag_dao.find (vt.tag_id) if (tag is not None - and (tag.name not in datum['tags']) + and (tag.name not in tag_names) and (tag.id_ is not None)): tag_ids.append (tag.id_) video_tag_dao.untag_all (video.id_, tag_ids, now) tags: list[TagDto] = [] - for tag_name in datum['tags']: + for tag_name in tag_names: tag = tag_dao.fetch_by_name (tag_name) if tag is None: tag = TagDto (name = tag_name) @@ -139,12 +140,12 @@ def update_tables ( vpos_ms = com['vposMs']) comment_dao.upsert (comment, False) - alive_video_ids = [d['contentId'] for d in api_data] + alive_video_codes = [d['contentId'] for d in api_data] lost_video_ids: list[int] = [] videos = video_dao.fetch_alive () for video in videos: - if video.id_ is not None and video.id_ not in alive_video_ids: + if video.id_ is not None and video.code not in alive_video_codes: lost_video_ids.append (video.id_) video_dao.delete (lost_video_ids, now) @@ -573,7 +574,7 @@ class VideoTagDao: self, video_id: int, tag_ids: list[int], - now: datetime + now: datetime, ) -> None: if not tag_ids: return