diff --git a/nico.py b/nico.py index 4fd8a28..419438a 100644 --- a/nico.py +++ b/nico.py @@ -29,7 +29,8 @@ KIRIBAN_VIEWS_COUNTS: list[int] = sorted ({ *range (1_000, 10_000, 1_000), *range (10_000, 1_000_001, 10_000), 194, 245, 510, 810, 114_514, 1_940, 2_450, 5_100, 19_400, 24_500, 51_000, 93_194, 2_424, 242_424, 1_919, - 4_545, 194_245, 245_194, 510_245 }) + 4_545, 194_245, 245_194, 510_245 }, + reverse = True) class VideoInfo (TypedDict): contentId: str @@ -134,17 +135,19 @@ def get_kiriban_list ( .max ('fetched_at'))) for kiriban_views_count in KIRIBAN_VIEWS_COUNTS: - targets = ({ vh.video.code for vh in (VideoHistory - .where ('fetched_at', latest_fetched_at) - .where ('views_count', '>=', kiriban_views_count) - .get ()) } - - { vh.video.code for vh in (VideoHistory - .where ('fetched_at', previous_fetched_at) - .where ('views_count', '>=', kiriban_views_count) - .get ()) }) + targets = { vh.video.code for vh in (VideoHistory + .where ('fetched_at', latest_fetched_at) + .where ('views_count', '>=', kiriban_views_count) + .get ()) } for code in targets: if code in [kiriban[1]['contentId'] for kiriban in kiriban_list]: continue + previous_views_count = cast (int, (VideoHistory + .where ('code', code) + .where ('fetched_at', '<', latest_fetched_at) + .max ('views_count'))) + if previous_views_count >= kiriban_views_count: + continue video_info = get_video_info (code) if video_info is not None: kiriban_list.append ((kiriban_views_count, video_info,