The dashboard (Raspberry Pi 3.5" screen + web pages), the end-to-end encrypted sync mailbox (PHP + SQLite) and the Android companion app (Flutter), with docs, clean-install checks and screenshots made from demo data. Built mostly with an AI coding assistant; not yet reviewed line by line by a human (see README and SECURITY.md). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
2.6 KiB
Python
69 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""The weather icons of the dashboard and the app, made from Meteocons (MIT, Bas Milius,
|
|
https://github.com/basmilius/meteocons): one PNG per OpenWeatherMap-style code ("01d", "10n" …),
|
|
the names both sides look up (the dashboard's weather.WMO maps the WMO codes onto them).
|
|
|
|
npm pack @meteocons/svg-static@0.1.0 && tar xzf meteocons-svg-static-0.1.0.tgz
|
|
pip install cairosvg
|
|
python3 tools/weather-icons.py package/fill
|
|
|
|
→ dashboard/plugins/weather/icons/<code>.png and app/assets/weather/<code>.png (the same files),
|
|
square, the margin trimmed, plus Meteocons' LICENSE next to them.
|
|
"""
|
|
import io
|
|
import os
|
|
import shutil
|
|
import sys
|
|
|
|
import cairosvg
|
|
from PIL import Image
|
|
|
|
REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
OUT = [os.path.join(REPO, "dashboard", "plugins", "weather", "icons"), os.path.join(REPO, "app", "assets", "weather")]
|
|
SIZE = 192
|
|
# code → (day, night): 01 clear, 02 mainly clear, 03 partly cloudy, 04 overcast, 09 drizzle / showers,
|
|
# 10 rain, 11 thunderstorm, 13 snow, 50 fog
|
|
ICONS = {
|
|
"01": ("clear-day", "clear-night"),
|
|
"02": ("partly-cloudy-day", "partly-cloudy-night"),
|
|
"03": ("overcast-day", "overcast-night"),
|
|
"04": ("overcast", "overcast"),
|
|
"09": ("drizzle", "drizzle"),
|
|
"10": ("rain", "rain"),
|
|
"11": ("thunderstorms-rain", "thunderstorms-rain"),
|
|
"13": ("snow", "snow"),
|
|
"50": ("fog", "fog"),
|
|
}
|
|
|
|
|
|
def render(svg):
|
|
im = Image.open(io.BytesIO(cairosvg.svg2png(url=svg, output_width=512, output_height=512))).convert("RGBA")
|
|
im = im.crop(im.getchannel("A").point(lambda a: 255 if a > 8 else 0).getbbox()) # the margin off
|
|
side = max(im.size)
|
|
sq = Image.new("RGBA", (side, side), (0, 0, 0, 0))
|
|
sq.paste(im, ((side - im.width) // 2, (side - im.height) // 2))
|
|
return sq.resize((SIZE, SIZE), Image.LANCZOS)
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) != 2:
|
|
sys.exit(__doc__)
|
|
src = sys.argv[1]
|
|
for d in OUT:
|
|
os.makedirs(d, exist_ok=True)
|
|
for f in os.listdir(d): # the previous set (e.g. other names) goes
|
|
if f.endswith(".png"):
|
|
os.remove(os.path.join(d, f))
|
|
for code, pair in ICONS.items():
|
|
for suffix, name in zip("dn", pair):
|
|
im = render(os.path.join(src, name + ".svg"))
|
|
for d in OUT:
|
|
im.save(os.path.join(d, f"{code}{suffix}.png"), optimize=True)
|
|
lic = os.path.join(os.path.dirname(os.path.abspath(src)), "LICENSE")
|
|
for d in OUT:
|
|
shutil.copyfile(lic, os.path.join(d, "LICENSE-meteocons.txt"))
|
|
print(f"{len(ICONS) * 2} icons → " + ", ".join(os.path.relpath(d, REPO) for d in OUT))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|