Browse Source

タグ周りのバグ修正

feature/query
みてるぞ 1 month ago
parent
commit
86238a11ed
1 changed files with 8 additions and 7 deletions
  1. +8
    -7
      update_db.py

+ 8
- 7
update_db.py View File

@@ -18,7 +18,7 @@ import requests


# TODO: “何もしなぃ” を意味する None と区別可能にするため,NULL クラスを別途用意すること # TODO: “何もしなぃ” を意味する None と区別可能にするため,NULL クラスを別途用意すること
DbNull = None DbNull = None
DbNullType = None
DbNullType = type (None)




class VideoSearchParam (TypedDict): class VideoSearchParam (TypedDict):
@@ -33,7 +33,7 @@ class VideoSearchParam (TypedDict):
class VideoResult (TypedDict): class VideoResult (TypedDict):
contentId: str contentId: str
title: str title: str
tags: list[str]
tags: str
description: str description: str
viewCounter: int viewCounter: int
startTime: str startTime: str
@@ -91,6 +91,7 @@ def update_tables (
) -> None: ) -> None:
video_ids: list[int] = [] video_ids: list[int] = []
for datum in api_data: for datum in api_data:
tag_names = datum['tags'].split ()
video = VideoDto (code = datum['contentId'], video = VideoDto (code = datum['contentId'],
title = datum['title'], title = datum['title'],
description = datum['description'], description = datum['description'],
@@ -107,12 +108,12 @@ def update_tables (
for vt in video_tags: for vt in video_tags:
tag = tag_dao.find (vt.tag_id) tag = tag_dao.find (vt.tag_id)
if (tag is not None 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)): and (tag.id_ is not None)):
tag_ids.append (tag.id_) tag_ids.append (tag.id_)
video_tag_dao.untag_all (video.id_, tag_ids, now) video_tag_dao.untag_all (video.id_, tag_ids, now)
tags: list[TagDto] = [] tags: list[TagDto] = []
for tag_name in datum['tags']:
for tag_name in tag_names:
tag = tag_dao.fetch_by_name (tag_name) tag = tag_dao.fetch_by_name (tag_name)
if tag is None: if tag is None:
tag = TagDto (name = tag_name) tag = TagDto (name = tag_name)
@@ -139,12 +140,12 @@ def update_tables (
vpos_ms = com['vposMs']) vpos_ms = com['vposMs'])
comment_dao.upsert (comment, False) 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] = [] lost_video_ids: list[int] = []
videos = video_dao.fetch_alive () videos = video_dao.fetch_alive ()
for video in videos: 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_) lost_video_ids.append (video.id_)


video_dao.delete (lost_video_ids, now) video_dao.delete (lost_video_ids, now)
@@ -573,7 +574,7 @@ class VideoTagDao:
self, self,
video_id: int, video_id: int,
tag_ids: list[int], tag_ids: list[int],
now: datetime
now: datetime,
) -> None: ) -> None:
if not tag_ids: if not tag_ids:
return return


Loading…
Cancel
Save