Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix: 移除 Takeout 的系统时区依赖

longmeidao6572c3c125bc
diff --git a/docs/STATUS.md b/docs/STATUS.md
index 4500d05fc..88bbc3c2b 100644
--- a/docs/STATUS.md
+++ b/docs/STATUS.md
@@ -86,7 +86,10 @@
分别为 67,104 / 35,166 / 44,367 / 2,225 / 14 条,首次新增 66,676 / 13 / 44,222 / 2,225 / 0,
无无法解析或跳过记录。与本机浏览器跨来源按同 URL、同秒的最大出现次数去重后,总库为
284,954 条,时间范围扩到 2023-06-14 至 2026-08-26;第二次 `--takeout-only` 导入五类新增均为
- 0。`--takeout-only` 用于浏览器仍在运行时隔离恢复旧导出,避免活库 backup 阻塞 Takeout 导入。
+ 0。Windows 拉取后首次回归发现其标准库没有 IANA `tzdata`,`ZoneInfo("Asia/Hong_Kong")`
+ 会让 Takeout 测试直接失败;HKT 在该导出中是固定 UTC+8,现改用标准库固定偏移,不再新增运行时
+ 依赖,Windows 全套 910 项通过。`--takeout-only` 用于浏览器仍在运行时隔离恢复旧导出,避免活库
+ backup 阻塞 Takeout 导入。
- 追更的「查找」在只读端一度返回 409:`/api/follow/resolve` 只联网发现、不碰账本,
却因为是 POST 被写入端闸门一并拦掉。已按 `READ_ONLY_POST_ROUTES` 白名单放行;
真正会写的 `check`/`save`/`status`/`source` 仍受闸门管辖。
diff --git a/src/peach/taste_history.py b/src/peach/taste_history.py
index 27e773851..06170aca3 100644
--- a/src/peach/taste_history.py
+++ b/src/peach/taste_history.py
@@ -11,11 +11,10 @@ import zipfile
from collections import Counter, defaultdict
from contextlib import closing
from dataclasses import dataclass
-from datetime import UTC, datetime, timedelta
+from datetime import UTC, datetime, timedelta, timezone
from html.parser import HTMLParser
from pathlib import Path
from urllib.parse import parse_qs, unquote, urlparse
-from zoneinfo import ZoneInfo
@dataclass(frozen=True)
@@ -75,6 +74,7 @@ TAKEOUT_ACTIVITY_ACTIONS = {"Visited", "Searched for", "Viewed", "Watched"}
TAKEOUT_DATE_RE = re.compile(
r"^(?P<date>[A-Z][a-z]{2} \d{1,2}, \d{4}, \d{1,2}:\d{2}:\d{2}\s+[AP]M) (?P<zone>HKT|UTC|GMT)$"
)
+HONG_KONG_TIMEZONE = timezone(timedelta(hours=8), name="HKT")
def discover_history_sources(
@@ -255,8 +255,8 @@ def _parse_takeout_date(value: str) -> datetime:
if not match:
raise ValueError("Google My Activity 时间格式无法识别")
naive = datetime.strptime(match.group("date"), "%b %d, %Y, %I:%M:%S %p")
- timezone = ZoneInfo("Asia/Hong_Kong") if match.group("zone") == "HKT" else UTC
- return naive.replace(tzinfo=timezone).astimezone(UTC)
+ source_timezone = HONG_KONG_TIMEZONE if match.group("zone") == "HKT" else UTC
+ return naive.replace(tzinfo=source_timezone).astimezone(UTC)
class _TakeoutActivityParser(HTMLParser):
diff --git a/tests/test_taste_history.py b/tests/test_taste_history.py
index 09b1b859f..4ec30ae87 100644
--- a/tests/test_taste_history.py
+++ b/tests/test_taste_history.py
@@ -5,10 +5,9 @@ import tempfile
import unittest
import zipfile
from contextlib import closing
-from datetime import UTC, datetime
+from datetime import UTC, datetime, timedelta, timezone
from pathlib import Path
from urllib.parse import quote
-from zoneinfo import ZoneInfo
from peach.taste_history import (
HistorySource,
@@ -75,7 +74,7 @@ class TasteHistoryTests(unittest.TestCase):
]
cards: list[str] = []
for url, timestamp, title in activity_rows:
- local = datetime.fromtimestamp(timestamp, UTC).astimezone(ZoneInfo("Asia/Hong_Kong"))
+ local = datetime.fromtimestamp(timestamp, UTC).astimezone(timezone(timedelta(hours=8)))
hour = (local.hour - 1) % 12 + 1
date = f"{local:%b} {local.day}, {local.year}, {hour}:{local:%M:%S} {local:%p} HKT"
wrapped = f"https://www.google.com/url?q={quote(url, safe='')}"