[books] Move one off creator to profile utils

This commit is contained in:
2025-07-20 16:31:20 -04:00
parent 9514861b32
commit 759caef45d
3 changed files with 68 additions and 41 deletions

View File

@ -12,6 +12,7 @@ from django.apps import apps
from django.contrib.auth import get_user_model
from stream_sqlite import stream_sqlite
from scrobbles.notifications import NtfyNotification
from vrobbler.apps.profiles.utils import one_off_fix_colins_profile
from webdav.client import get_webdav_client
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
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(
book_map: dict, user: "User"
@ -308,14 +280,20 @@ def build_scrobbles_from_book_map(
)
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:
one_off_fix_colins_profile(user.profile)
# 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)
stop_timestamp = stop_timestamp - timedelta(hours=1)
else:
@ -349,7 +327,7 @@ def build_scrobbles_from_book_map(
in_progress=False,
played_to_completion=True,
long_play_complete=False,
timezone=timestamp.tzinfo.name
timezone=timestamp.tzinfo.name,
)
)
# Then start over