feat: content provenance and complete frame management workflows

This commit is contained in:
Pigway
2026-10-02 09:19:25 +08:00
parent f7c890c551
commit e67b4ceb6e
18 changed files with 918 additions and 18 deletions
+25 -3
View File
@@ -46,7 +46,7 @@ class TemplateRenderer:
return ImageFont.truetype(path, size)
return ImageFont.load_default(size=size)
def render(self, template_id, data, profile="color"):
def resolve(self, template_id, data):
spec = self.info(template_id)
conf = self.db.one(
"SELECT payload FROM template_config WHERE template_id=?", (template_id,)
@@ -69,8 +69,20 @@ class TemplateRenderer:
"星期日 / Sunday",
][current.weekday()],
)
values.setdefault("weather", self.weather.get_current())
if "weather" not in values:
values["weather"] = self.weather.get_current()
values["updated"] = current.strftime("%Y-%m-%d %H:%M")
values["weather_attribution"] = (
values.get("weather", {}).get("attribution", "")
if isinstance(values.get("weather"), dict)
else ""
)
return values
def render(self, template_id, data, profile="color"):
spec = self.info(template_id)
values = self.resolve(template_id, data)
current = datetime.now(ZoneInfo(self.settings.timezone))
img = Image.new("RGB", (1200, 1600), "white")
draw = ImageDraw.Draw(img)
accent = "#184d42" if profile == "color" else "#000000"
@@ -156,7 +168,17 @@ class TemplateRenderer:
for v in value[:10]
)
if isinstance(value, dict):
value = " · ".join(str(v) for k, v in value.items() if k != "mock")
if block.get("field") == "weather":
value = " · ".join(
str(value.get(k, ""))
for k in ["location", "temperature", "summary"]
)
if values["weather"].get("stale"):
value += " · 数据过期 / Stale"
else:
value = " · ".join(
str(v) for k, v in value.items() if k != "mock"
)
text(value, x, y, w, h, block.get("size", 40))
if profile == "grayscale":
img = ImageOps.grayscale(img).convert("RGB")