Compare commits

...

2 Commits

5 changed files with 67 additions and 11 deletions

View File

@ -1 +1 @@
0.2.14
0.2.16

View File

@ -59,8 +59,10 @@ def missing_message_dates(
overwrite: bool = False,
refresh_tagged_from: date | None = None,
daily_overwrite_from: date | None = None,
already_overwritten: set[str] | None = None,
):
"""Yield message days that are missing or explicitly tagged for refresh."""
"""Yield message days that are missing, tagged, or pending overwrite."""
overwritten = already_overwritten or set()
current = start
while current <= end:
output = Path(output_for_day(current))
@ -70,7 +72,11 @@ def missing_message_dates(
and current >= refresh_tagged_from
and has_missing_report_tag(output)
)
forced = daily_overwrite_from is not None and current >= daily_overwrite_from
forced = (
daily_overwrite_from is not None
and current >= daily_overwrite_from
and current.isoformat() not in overwritten
)
if (overwrite or not exists or refresh or forced) and has_messages(current):
yield current
current += timedelta(days=1)
@ -224,6 +230,15 @@ def main():
flush=True,
)
state_path = Path(args.state).expanduser()
previous_overwritten: set[str] = set()
if state_path.exists():
try:
previous = json.loads(state_path.read_text(encoding="utf-8"))
previous_overwritten = set(previous.get("overwritten_dates", []))
except (ValueError, OSError):
previous_overwritten = set()
state = {
"model": args.model,
"start_date": start.isoformat(),
@ -235,8 +250,8 @@ def main():
"failed": 0,
"last_completed": None,
"last_attempted": None,
"overwritten_dates": sorted(previous_overwritten),
}
state_path = Path(args.state).expanduser()
write_state(state_path, state)
print(
f"补日志范围: {daily_start} 至 {end};"
@ -244,7 +259,7 @@ def main():
flush=True,
)
def run_step(command, output, label, kind="daily"):
def run_step(command, output, label, kind="daily", day: date | None = None):
state["last_attempted"] = label
write_state(state_path, state)
print(f"===== {label} 开始 =====", flush=True)
@ -259,6 +274,10 @@ def main():
state[key] += 1
state_key = {"daily": "last_completed", "weekly": "last_weekly_completed", "monthly": "last_monthly_completed"}[kind]
state[state_key] = label
if day is not None:
overwritten = set(state.get("overwritten_dates", []))
overwritten.add(day.isoformat())
state["overwritten_dates"] = sorted(overwritten)
write_state(state_path, state)
print(f"===== {label} 完成 =====", flush=True)
return 0
@ -321,6 +340,7 @@ def main():
args.overwrite,
refresh_tagged_from,
daily_overwrite_from,
set(state["overwritten_dates"]),
):
command = [
sys.executable, str(ROOT / "lark_snooper.py"), "summarize",
@ -338,7 +358,9 @@ def main():
or (daily_overwrite_from and day >= daily_overwrite_from)
):
command.append("--overwrite")
result = run_step(command, output, f"补日志 {day}")
result = run_step(
command, output, f"补日志 {day}", kind="daily", day=day
)
if result:
return result

View File

@ -43,6 +43,11 @@ def _extract_topic(text: str) -> str:
return match.group(1).strip() if match else ""
def _drop_permission_change(links: list[dict[str, Any]]) -> list[dict[str, Any]]:
"""Permission-change notices carry no title and are not new minutes."""
return [link for link in links if "permission_change" not in link["url"]]
def fetch_ai_notes_links(
client: Any,
target_day: date,
@ -104,10 +109,12 @@ def fetch_ai_notes_links(
# If we found links locally, return them sorted
if links:
links.sort(key=lambda x: x["create_time"])
return links
return _drop_permission_change(links)
# Otherwise pull from network
return _fetch_ai_notes_links_from_network(client, target_day, tz, chat_id, storage)
return _drop_permission_change(
_fetch_ai_notes_links_from_network(client, target_day, tz, chat_id, storage)
)
def _fetch_ai_notes_links_from_network(

View File

@ -97,3 +97,19 @@ def test_backfill_does_not_probe_days_that_do_not_need_regeneration(tmp_path):
assert days == []
assert probes == [] # 已存在且无需重生成的日子不应触发拉取判断
def test_daily_overwrite_skips_dates_already_overwritten(tmp_path):
for day in (date(2026, 11, 11), date(2026, 11, 12)):
(tmp_path / f"{day.isoformat()}.md").write_text("旧日报", encoding="utf-8")
days = list(missing_message_dates(
date(2026, 11, 11),
date(2026, 11, 12),
lambda day: True,
lambda day: tmp_path / f"{day.isoformat()}.md",
daily_overwrite_from=date(2026, 11, 11),
already_overwritten={"2026-11-11"},
))
assert days == [date(2026, 11, 12)]

View File

@ -48,15 +48,26 @@ def test_fetch_ai_notes_links_reads_topic_from_local_content():
),
})
links = fetch_ai_notes_links(
object(), date(2026, 11, 17), tz, storage=storage
)
links = fetch_ai_notes_links(object(), date(2026, 11, 17), tz, storage=storage)
assert len(links) == 1
assert links[0]["url"].startswith("https://efund.feishu.cn/minutes/abc123")
assert links[0]["topic"] == "指数-金科定期AI业务讨论会"
def test_permission_change_links_are_dropped():
from snooper_calendar import _drop_permission_change
links = [
{"url": "https://efund.feishu.cn/minutes/m1?from_source=permission_change"},
{"url": "https://efund.feishu.cn/minutes/m2?from_source=finish_recording"},
]
kept = _drop_permission_change(links)
assert [link["url"] for link in kept] == [
"https://efund.feishu.cn/minutes/m2?from_source=finish_recording"
]
class FakeCalendarClient:
def __init__(self):
self.calls = []