feat: finish forecast rendering and account-authenticated API explorer

This commit is contained in:
Pigway
2026-10-02 09:27:44 +08:00
parent e67b4ceb6e
commit d10b07c464
8 changed files with 83 additions and 10 deletions
+16 -1
View File
@@ -71,6 +71,13 @@ class TemplateRenderer:
)
if "weather" not in values:
values["weather"] = self.weather.get_current()
if (
any(b.get("field") == "forecast" for b in spec["blocks"])
and "forecast" not in values
):
values["forecast"] = self.weather.get_forecast() or [
"尚无天气预报 / No forecast available"
]
values["updated"] = current.strftime("%Y-%m-%d %H:%M")
values["weather_attribution"] = (
values.get("weather", {}).get("attribution", "")
@@ -164,7 +171,15 @@ class TemplateRenderer:
if isinstance(value, list):
value = "\n".join(
"• "
+ (str(v.get("title", "")) if isinstance(v, dict) else str(v))
+ (
(
f"{v.get('date', '')} · {v.get('summary', '')} · {v.get('minimum_c', '--')}–{v.get('maximum_c', '--')}°C · {v.get('rain_probability', '--')}%"
if block.get("field") == "forecast"
else str(v.get("title", ""))
)
if isinstance(v, dict)
else str(v)
)
for v in value[:10]
)
if isinstance(value, dict):