feat: 完善日报人物来源与会议链接
This commit is contained in:
@ -11,8 +11,28 @@ class CalendarError(RuntimeError):
|
||||
"""Calendar retrieval failed without exposing event contents."""
|
||||
|
||||
|
||||
def resolve_calendar_links(config: dict[str, Any]) -> dict[str, str]:
|
||||
"""Validate manual date|summary to meeting-link mappings."""
|
||||
links = config.get("calendar", {}).get("meeting_links", {})
|
||||
if links is None:
|
||||
return {}
|
||||
if not isinstance(links, dict):
|
||||
raise CalendarError("YAML 的 calendar.meeting_links 必须是映射。")
|
||||
resolved = {}
|
||||
for key, url in links.items():
|
||||
if not isinstance(key, str) or not isinstance(url, str):
|
||||
raise CalendarError("会议链接的键和 URL 必须是字符串。")
|
||||
if not url.startswith(("https://", "http://")):
|
||||
raise CalendarError("会议链接必须是 HTTP(S) URL。")
|
||||
resolved[key] = url
|
||||
return resolved
|
||||
|
||||
|
||||
def fetch_calendar_events(
|
||||
client: Any, target_day: date, tz: ZoneInfo
|
||||
client: Any,
|
||||
target_day: date,
|
||||
tz: ZoneInfo,
|
||||
meeting_links: dict[str, str] | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Return normalized primary-calendar instances for one natural day."""
|
||||
start = datetime.combine(target_day, time.min, tzinfo=tz)
|
||||
@ -46,9 +66,14 @@ def fetch_calendar_events(
|
||||
for location in locations
|
||||
if isinstance(location, dict) and location.get("name")
|
||||
]
|
||||
summary = str(event.get("summary") or "未命名会议")
|
||||
native_url = str(event.get("meetingMinuteUrl") or event.get("url") or "")
|
||||
manual_url = (meeting_links or {}).get(
|
||||
f"{target_day.isoformat()}|{summary}", ""
|
||||
)
|
||||
events.append(
|
||||
{
|
||||
"summary": str(event.get("summary") or "未命名会议"),
|
||||
"summary": summary,
|
||||
"begin": datetime.fromtimestamp(
|
||||
int(instance["beginTime"]), tz
|
||||
).isoformat(timespec="seconds"),
|
||||
@ -57,9 +82,7 @@ def fetch_calendar_events(
|
||||
).isoformat(timespec="seconds"),
|
||||
"location": ";".join(location_names),
|
||||
"cancelled": bool(event.get("isDeleted")),
|
||||
"url": str(
|
||||
event.get("meetingMinuteUrl") or event.get("url") or ""
|
||||
),
|
||||
"url": native_url or manual_url,
|
||||
}
|
||||
)
|
||||
events.sort(key=lambda event: (event["begin"], event["summary"]))
|
||||
|
||||
Reference in New Issue
Block a user