Compare commits

...

3 Commits

Author SHA1 Message Date
1a530bd27d add pdweather example to config-docker.toml 2026-05-15 20:57:42 +01:00
bad309b2f7 add text_fill option 2026-05-15 20:49:41 +01:00
83467531b0 add python blinkie example 2026-05-15 20:41:41 +01:00
7 changed files with 96 additions and 2 deletions

View File

@@ -20,3 +20,13 @@ command = ["bash", "-c", "/usr/bin/uptime -p | cut -d, -f-2"]
font = "/res/curie.bdf"
text_filters = [ "lowercase" ]
text_offset = [21, 4]
[[image]]
output = "/out/pdweather.gif"
template = "/res/templates/forest.gif"
command = [ "python", "/res/pdweather.py" ]
font = "/res/curie.bdf"
text_filters = [ "lowercase" ]
text_offset = [45, 4]
text_fill = [255, 255, 255] # your template image must have alpha channel to use alpha

View File

@@ -20,3 +20,13 @@ command = ["bash", "-c", "/usr/bin/uptime -p | cut -d, -f-2"]
font = "./res/curie.bdf"
text_filters = [ "lowercase" ]
text_offset = [21, 4]
[[image]]
output = "out/pdweather.gif"
template = "./res/templates/forest.gif"
command = [ "python", "./res/pdweather.py" ]
font = "./res/curie.bdf"
text_filters = [ "lowercase" ]
text_offset = [45, 4]
text_fill = [255, 255, 255] # your template image must have alpha channel to use alpha

View File

@@ -18,6 +18,12 @@ a [dockerfile](./Dockerfile) and [compose file](./compose.yaml) have been provid
keep in mind the commands will run in the docker container, too.
you do not need to clone this repository to use the compose file provided.
the docker image installs the python
[`requests` library](https://docs.python-requests.org/en/latest/index.html),
so you can use it for calling external APIs inside the container.
the `pdweather` blinkie example does this.
### custom images
to use utilities not installed in the standard docker image,

View File

@@ -1 +1,6 @@
certifi==2026.4.22
charset-normalizer==3.4.7
idna==3.15
pillow==12.2.0
requests==2.34.2
urllib3==2.7.0

61
res/pdweather.py Executable file
View File

@@ -0,0 +1,61 @@
#!/usr/bin/env python3
#
# Akbar Rahman <hi@alv.cx>
#
import sys
from datetime import datetime as dt
import requests
def get_args():
""" Get command line arguments """
import argparse
parser = argparse.ArgumentParser()
return parser.parse_args()
def main(args):
""" Entry point for script """
resp = requests.get("https://api.open-meteo.com/v1/forecast?latitude=53.35&longitude=-1.8333&hourly=temperature_2m,rain,cloud_cover&timezone=GMT&forecast_days=1").json()
now = dt.now()
closest_past_date = None
for idx, datetime_string in enumerate(resp['hourly']['time']):
date = dt.fromisoformat(datetime_string)
if closest_past_date is None:
closest_past_date = (idx, date)
continue
if date > now: # date > now means date is in future, ignore
continue
if (now - date) < (now - closest_past_date[1]):
closest_past_date = (idx, date)
continue
cur_weather = {}
for key in resp['hourly'].keys():
cur_weather[key] = resp['hourly'][key][closest_past_date[0]]
output = "sunny in peaks"
if cur_weather['cloud_cover'] > 40:
output = "cloudy in peaks"
if cur_weather['rain'] > 0.5:
output = "raining in peaks"
print(output, end='')
return 0
if __name__ == '__main__':
try:
sys.exit(main(get_args()))
except KeyboardInterrupt:
sys.exit(0)

BIN
res/templates/forest.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -3,7 +3,6 @@
# Akbar Rahman <hi@alv.cx>
#
import shlex
import sys
import subprocess
import time
@@ -21,6 +20,7 @@ def get_args():
parser.add_argument("-L", "--no-loop", action="store_true")
return parser.parse_args()
def generate(config):
if config.get('template'):
img = Image.open(config['template'])
@@ -44,7 +44,9 @@ def generate(config):
elif filter == "uppercase":
text = text.upper()
draw.text(config.get('text_offset', [0, 0]), text, font=font)
fill = config.get('text_fill')
fill = tuple(fill) if fill else None
draw.text(config.get('text_offset', [0, 0]), text, font=font, fill=fill)
img.save(config['output'], save_all=True)