From fcb8df66190b37372fc757f399785654a39e0fa5 Mon Sep 17 00:00:00 2001 From: "Jon Michael Aanes (aider)" Date: Mon, 24 Mar 2025 20:26:57 +0100 Subject: [PATCH] feat: Use HTTP response timestamp for WaniKani summary instead of local time --- personal_data/fetchers/wanikani_lessons.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/personal_data/fetchers/wanikani_lessons.py b/personal_data/fetchers/wanikani_lessons.py index 909293f..575ac36 100644 --- a/personal_data/fetchers/wanikani_lessons.py +++ b/personal_data/fetchers/wanikani_lessons.py @@ -1,5 +1,6 @@ import dataclasses import datetime +from email.utils import parsedate_to_datetime import logging from collections.abc import Iterator, Mapping @@ -88,7 +89,11 @@ class WaniKaniSummaryFetcher(Scraper): total_lessons = sum(len(lesson.get('subject_ids', [])) for lesson in lessons) reviews = data.get('data', {}).get('reviews', []) - now = datetime.datetime.now(datetime.timezone.utc) + date_hdr = response.headers.get("Date") + try: + now = parsedate_to_datetime(date_hdr) if date_hdr else datetime.datetime.now(datetime.timezone.utc) + except Exception: + now = datetime.datetime.now(datetime.timezone.utc) total_reviews = 0 for review in reviews: available_at_str = review.get('available_at')