瀏覽代碼

[books] Move one off creator to profile utils

Colin Powell 2 月之前
父節點
當前提交
759caef45d
共有 3 個文件被更改,包括 68 次插入41 次删除
  1. 15 6
      PROJECT.org
  2. 11 33
      vrobbler/apps/books/koreader.py
  3. 42 2
      vrobbler/apps/profiles/utils.py

+ 15 - 6
PROJECT.org

@@ -79,7 +79,14 @@ fetching and simple saving.
 :LOGBOOK:
 :LOGBOOK:
 CLOCK: [2025-07-09 Wed 09:55]--[2025-07-09 Wed 10:15] =>  0:20
 CLOCK: [2025-07-09 Wed 09:55]--[2025-07-09 Wed 10:15] =>  0:20
 :END:
 :END:
-* Backlog [3/23]
+* Backlog [4/27]
+** STRT Only create a LastFM import if there are files to import :vrobbler:feature:lastfm:importers:project:personal:
+:PROPERTIES:
+:ID:       7a1456af-c5f1-6385-b34f-0be24a6b65b0
+:END:
+- Note taken on [2025-07-20 Sun 16:21]
+
+  This thing is kicking my butt. As it stands it works, but the scrobbles are not assigned to the tracks properly.
 ** TODO Add timezone awarness to IMAP importer :personal:project:vrobbler:feature:importer:imap:timezones:
 ** TODO Add timezone awarness to IMAP importer :personal:project:vrobbler:feature:importer:imap:timezones:
 ** DONE Track timezone changes for profiles :vrobbler:feature:profiles:personal:project:
 ** DONE Track timezone changes for profiles :vrobbler:feature:profiles:personal:project:
 :PROPERTIES:
 :PROPERTIES:
@@ -94,10 +101,9 @@ CLOCK: [2025-07-09 Wed 09:55]--[2025-07-09 Wed 10:15] =>  0:20
 CLOCK: [2025-07-09 Wed 10:15]
 CLOCK: [2025-07-09 Wed 10:15]
 :END:
 :END:
 
 
-** TODO [#A] Geolocation notifications should go out for named locations :vrobbler:feature:geoloc:personal:project:
-:PROPERTIES:
-:ID:       5d086625-877c-df81-15b8-7ae0bc1ba2fc
-:END:
+** TODO Look in comments for a timestamp for start from BG stats if the time is missing :vrobbler:feature:boardgames:project:personal:
+** TODO Add importer class for IMAP imports :vrobbler:feature:imap:importers:project:personal:
+** TODO Add youtube link in place of IMDB on video detail page :vrobbler:feature:videos:personal:project:
 ** TODO [#A] Tasks from org-mode should properly update notes and leave them out of the body :vrobbler:bug:tasks:
 ** TODO [#A] Tasks from org-mode should properly update notes and leave them out of the body :vrobbler:bug:tasks:
 ** TODO [#A] Fix small bug in views for TV series where next episode is now None :vrobbler:bug:personal:videos:
 ** TODO [#A] Fix small bug in views for TV series where next episode is now None :vrobbler:bug:personal:videos:
 
 
@@ -135,7 +141,6 @@ The page data has the canonical date something was read in it, but it seems to b
 
 
 Also, we'd need to adjust any old scrobbles that took place with DST off to roll them back by an hour.
 Also, we'd need to adjust any old scrobbles that took place with DST off to roll them back by an hour.
 ** TODO [#A] Create small utility to clean up tracks scrobbled with wonky playback times :vrobbler:personal:bug:music:scrobbles:
 ** TODO [#A] Create small utility to clean up tracks scrobbled with wonky playback times :vrobbler:personal:bug:music:scrobbles:
-** TODO [#B] Aservicedd youtube link in place of IMDB on video detail page :vrobbler:feature:videos:personal:project:
 ** TODO [#B] Add AllTrails as a source for Trail data :vrobbler:trails:feature:personal:project:
 ** TODO [#B] Add AllTrails as a source for Trail data :vrobbler:trails:feature:personal:project:
 Pretty clear, I would love to make trails more useful. Historically I wasn't
 Pretty clear, I would love to make trails more useful. Historically I wasn't
 hiking a lot, which made the source for this a bit silly. But it's clear that
 hiking a lot, which made the source for this a bit silly. But it's clear that
@@ -451,6 +456,10 @@ it's annoying.
 ** TODO [#C] Allow users to see tasks on calendar view :vrobbler:personal:project:templates:feature:
 ** TODO [#C] Allow users to see tasks on calendar view :vrobbler:personal:project:templates:feature:
 https://codepen.io/oliviale/pen/QYqybo
 https://codepen.io/oliviale/pen/QYqybo
 ** TODO [#C] Come up with a possible flow using WebDAV and super-productivity for tasks :personal:feature:project:vrobbler:tasks:
 ** TODO [#C] Come up with a possible flow using WebDAV and super-productivity for tasks :personal:feature:project:vrobbler:tasks:
+** DONE Import from BG stats a "learning" log field when "Learning to play" is in the comment :vrobbler:feature:boardgames:project:personal:
+:PROPERTIES:
+:ID:       fda59fab-4349-e99e-54c6-9f1392a1c474
+:END:
 ** DONE [#A] Add email importer for BG stats file uploads :vrobbler:feature:boardgames:personal:project:
 ** DONE [#A] Add email importer for BG stats file uploads :vrobbler:feature:boardgames:personal:project:
 :PROPERTIES:
 :PROPERTIES:
 :ID:       116fe738-7966-615c-d195-ccff0337b101
 :ID:       116fe738-7966-615c-d195-ccff0337b101

+ 11 - 33
vrobbler/apps/books/koreader.py

@@ -12,6 +12,7 @@ from django.apps import apps
 from django.contrib.auth import get_user_model
 from django.contrib.auth import get_user_model
 from stream_sqlite import stream_sqlite
 from stream_sqlite import stream_sqlite
 from scrobbles.notifications import NtfyNotification
 from scrobbles.notifications import NtfyNotification
+from vrobbler.apps.profiles.utils import one_off_fix_colins_profile
 from webdav.client import get_webdav_client
 from webdav.client import get_webdav_client
 
 
 logger = logging.getLogger(__name__)
 logger = logging.getLogger(__name__)
@@ -209,35 +210,6 @@ def build_page_data(page_rows: list, book_map: dict, user_tz=None) -> dict:
         )
         )
     return book_map
     return book_map
 
 
-def one_off_fix_colins_profile(profile):
-    home_tz = "America/New_York"
-
-    europe = "2023-10-15"
-    europe_tz = "Europe/Paris"
-    europe_end = "2023-12-15"
-
-    washington = "2023-10-15"
-    washington_tz = "America/Los_Angeles"
-    washington_end = "2023-05-04"
-
-    camp = "2024-08-04"
-    camp_end = "2024-08-10"
-    camp_tz = "America/Halifax"
-
-    summer = "2025-07-10"
-    summer_end = "2025-07-13"
-    summer_tz = "America/Los_Angeles"
-
-    profile.timezone_change_log = ""
-    profile.timezone_change_log += f"{europe_tz} - {pendulum.parse(europe)}\n"
-    profile.timezone_change_log += f"{home_tz} - {pendulum.parse(europe_end)}\n"
-    profile.timezone_change_log += f"{washington_tz} - {pendulum.parse(washington)}\n"
-    profile.timezone_change_log += f"{home_tz} - {pendulum.parse(washington_end)}\n"
-    profile.timezone_change_log += f"{camp_tz} - {pendulum.parse(camp)}\n"
-    profile.timezone_change_log += f"{home_tz} - {pendulum.parse(camp_end)}\n"
-    profile.timezone_change_log += f"{summer_tz} - {pendulum.parse(summer)}\n"
-    profile.timezone_change_log += f"{home_tz} - {pendulum.parse(summer_end)}\n"
-    profile.save()
 
 
 def build_scrobbles_from_book_map(
 def build_scrobbles_from_book_map(
     book_map: dict, user: "User"
     book_map: dict, user: "User"
@@ -308,14 +280,20 @@ def build_scrobbles_from_book_map(
                     )
                     )
                     continue
                     continue
 
 
-                timestamp = user.profile.get_timestamp_with_tz(datetime.fromtimestamp(int(first_page.get("start_ts"))))
-                stop_timestamp = user.profile.get_timestamp_with_tz(datetime.fromtimestamp(int(last_page.get("end_ts"))))
+                timestamp = user.profile.get_timestamp_with_tz(
+                    datetime.fromtimestamp(int(first_page.get("start_ts")))
+                )
+                stop_timestamp = user.profile.get_timestamp_with_tz(
+                    datetime.fromtimestamp(int(last_page.get("end_ts")))
+                )
 
 
                 if user.id == 1 and not user.profile.timezone_change_log:
                 if user.id == 1 and not user.profile.timezone_change_log:
                     one_off_fix_colins_profile(user.profile)
                     one_off_fix_colins_profile(user.profile)
 
 
                 # Adjust for Daylight Saving Time
                 # Adjust for Daylight Saving Time
-                if timestamp.dst() == timedelta(0) or stop_timestamp.dst() == timedelta(0):
+                if timestamp.dst() == timedelta(
+                    0
+                ) or stop_timestamp.dst() == timedelta(0):
                     timestamp = timestamp - timedelta(hours=1)
                     timestamp = timestamp - timedelta(hours=1)
                     stop_timestamp = stop_timestamp - timedelta(hours=1)
                     stop_timestamp = stop_timestamp - timedelta(hours=1)
                 else:
                 else:
@@ -349,7 +327,7 @@ def build_scrobbles_from_book_map(
                             in_progress=False,
                             in_progress=False,
                             played_to_completion=True,
                             played_to_completion=True,
                             long_play_complete=False,
                             long_play_complete=False,
-                            timezone=timestamp.tzinfo.name
+                            timezone=timestamp.tzinfo.name,
                         )
                         )
                     )
                     )
                 # Then start over
                 # Then start over

+ 42 - 2
vrobbler/apps/profiles/utils.py

@@ -1,9 +1,10 @@
+from datetime import datetime, timedelta
+
+import pendulum
 import pytz
 import pytz
 from django.conf import settings
 from django.conf import settings
 from django.utils import timezone
 from django.utils import timezone
-import calendar
 
 
-from datetime import datetime, timedelta
 
 
 # need to translate to a non-naive timezone, even if timezone == settings.TIME_ZONE, so we can compare two dates
 # need to translate to a non-naive timezone, even if timezone == settings.TIME_ZONE, so we can compare two dates
 def to_user_timezone(date, profile):
 def to_user_timezone(date, profile):
@@ -56,3 +57,42 @@ def end_of_month(dt, profile) -> datetime:
 
 
 def start_of_year(dt, profile) -> datetime:
 def start_of_year(dt, profile) -> datetime:
     return start_of_day(dt, profile).replace(month=1, day=1)
     return start_of_day(dt, profile).replace(month=1, day=1)
+
+
+def one_off_fix_colins_profile(profile):
+    home_tz = "America/New_York"
+
+    europe = "2022-10-15"
+    europe_tz = "Europe/Paris"
+    europe_end = "2023-12-15"
+
+    washington = "2023-04-28"
+    washington_tz = "America/Los_Angeles"
+    washington_end = "2023-05-04"
+
+    camp = "2024-08-04"
+    camp_end = "2024-08-10"
+    camp_tz = "America/Halifax"
+
+    summer = "2025-07-09 12:00:00"
+    summer_end = "2025-07-13 20:30:00"
+    summer_tz = "America/Los_Angeles"
+
+    profile.timezone_change_log = ""
+    profile.timezone_change_log += f"{europe_tz} - {pendulum.parse(europe)}\n"
+    profile.timezone_change_log += (
+        f"{home_tz} - {pendulum.parse(europe_end)}\n"
+    )
+    profile.timezone_change_log += (
+        f"{washington_tz} - {pendulum.parse(washington)}\n"
+    )
+    profile.timezone_change_log += (
+        f"{home_tz} - {pendulum.parse(washington_end)}\n"
+    )
+    profile.timezone_change_log += f"{camp_tz} - {pendulum.parse(camp)}\n"
+    profile.timezone_change_log += f"{home_tz} - {pendulum.parse(camp_end)}\n"
+    profile.timezone_change_log += f"{summer_tz} - {pendulum.parse(summer)}\n"
+    profile.timezone_change_log += (
+        f"{home_tz} - {pendulum.parse(summer_end)}\n"
+    )
+    profile.save()