|
|
|
@@ -11,12 +11,12 @@ import json |
|
|
|
import os |
|
|
|
import sys |
|
|
|
from datetime import date, datetime |
|
|
|
from typing import TypedDict |
|
|
|
from typing import TypedDict, cast |
|
|
|
|
|
|
|
from eloquent import DatabaseManager, Model |
|
|
|
|
|
|
|
from db.config import DB |
|
|
|
from db.models import VideoHistory |
|
|
|
from db.models import Video, VideoHistory |
|
|
|
|
|
|
|
DB |
|
|
|
|
|
|
|
@@ -26,9 +26,9 @@ def main ( |
|
|
|
base_date: date, |
|
|
|
) -> None: |
|
|
|
if not base_date: |
|
|
|
base_date = date.now () |
|
|
|
base_date = datetime.now ().date () |
|
|
|
|
|
|
|
kiriban_list: list[list[int, str, str]] = [] |
|
|
|
kiriban_list: list[tuple[int, str, str]] = [] |
|
|
|
|
|
|
|
latest_fetched_at = cast (date, (VideoHistory |
|
|
|
.where ('fetched_at', '<=', base_date) |
|
|
|
@@ -47,7 +47,7 @@ def main ( |
|
|
|
|
|
|
|
previous_views_count: int | None = ( |
|
|
|
VideoHistory |
|
|
|
.where_has ('viedo', lambda q, code = code: q.where ('code', code)) |
|
|
|
.where_has ('viedos', lambda q, code = code: q.where ('code', code)) |
|
|
|
.where ('fetched_at', '<', latest_fetched_at) |
|
|
|
.max ('views_count')) |
|
|
|
if previous_views_count is None: |
|
|
|
@@ -55,12 +55,13 @@ def main ( |
|
|
|
if previous_views_count >= views_count: |
|
|
|
continue |
|
|
|
|
|
|
|
kiriban_list.append ([views_count, code, |
|
|
|
kiriban_list.append ((views_count, code, |
|
|
|
(cast (Video, Video.where ('code', code).first ()) |
|
|
|
.uploaded_at)]) |
|
|
|
.uploaded_at))) |
|
|
|
|
|
|
|
print (json.dumps (kiriban_list, default = str)) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
main (sys.argv[2:], datetime.strptime (sys.argv[1], '%Y-%m-%d').date ()) |
|
|
|
main (map (int, sys.argv[2:]), |
|
|
|
datetime.strptime (sys.argv[1], '%Y-%m-%d').date ()) |