فهرست منبع

[moods] Add mood fixture data

Colin Powell 8 ماه پیش
والد
کامیت
047dd22069

+ 42 - 0
vrobbler/apps/books/management/commands/cleanup_book_scrobble_times.py

@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+import logging
+import pytz
+from datetime import datetime, timedelta
+from books.models import Book
+from django.core.management.base import BaseCommand
+from scrobbles.models import Scrobble
+from vrobbler.apps.books.koreader import fix_long_play_stats_for_scrobbles
+from vrobbler.apps.scrobbles.utils import timestamp_user_tz_to_utc
+
+
+logger = logging.getLogger(__name__)
+
+# Grace period between page reads for it to be a new scrobble
+SESSION_GAP_SECONDS = 1800  #  a half hour
+
+def update_scrobble_from_page_data(scrobble, commit=True):
+    page_list = list(scrobble.book_page_data.items())
+    first_page_start_ts = datetime.fromtimestamp(page_list[0][1]["start_ts"])
+    last_page_end_ts = datetime.fromtimestamp(page_list[-1][1]["end_ts"])
+
+    if (
+        datetime(2023, 10, 15) <= first_page_start_ts <= datetime(2023, 12, 15)
+    ):
+        first_page_start_ts.replace(tzinfo=pytz.timezone("Europe/Paris"))
+        last_page_end_ts.replace(tzinfo=pytz.timezone("Europe/Paris"))
+    else:
+        first_page_start_ts.replace(tzinfo=pytz.timezone("US/Eastern"))
+        last_page_end_ts.replace(tzinfo=pytz.timezone("US/Eastern"))
+
+    scrobble.timestamp = first_page_start_ts
+    scrobble.stop_timestamp = last_page_end_ts
+    if commit:
+        scrobble.save(update_fields=["timestamp", "stop_timestamp"])
+
+
+class Command(BaseCommand):
+    def handle(self, *args, **options):
+        scrobbles_to_create = []
+
+        for scrobble in Scrobble.objects.filter(media_type="Book", source="KOReader"):
+            update_scrobble_from_page_data(scrobble)

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
vrobbler/apps/moods/fixtures/moods.json


برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است