allow args. README.

This commit is contained in:
Christoph Haas 2026-01-16 23:52:42 +01:00
parent 529262ea4d
commit f10caa3918
7 changed files with 71 additions and 16 deletions

View file

@ -2,7 +2,7 @@
import time
from PIL import Image, ImageDraw
from lib import display
import lib.display
# Replace with your free Finnhub API key
API_KEY = "d3t8099r01qigeg1s7cgd3t8099r01qigeg1s7d0"
@ -12,14 +12,18 @@ finnhub_client = finnhub.Client(api_key="d3t8099r01qigeg1s7cgd3t8099r01qigeg1s7d
def get_bitcoin_price():
symbol = "BINANCE:BTCEUR"
data = finnhub_client.quote(symbol)
#print("getting finnhub")
return data['c']
def start(image_buffer, stop_event, text="Hello World!"):
def start(stop_event, args):
last_price = None
trend = None
image_buffer = lib.display.matrix.buffer()
draw = ImageDraw.Draw(image_buffer)
symbol = ''
while not stop_event.is_set():
image_buffer = Image.new("RGB", (128, 64))
draw = ImageDraw.Draw(image_buffer)
# All to black
draw.rectangle( ((0,0),(lib.display.matrix.width-1,lib.display.matrix.height-1)), fill=(0,0,0) )
price = get_bitcoin_price()
@ -27,16 +31,19 @@ def start(image_buffer, stop_event, text="Hello World!"):
if last_price:
if price > last_price:
trend = 1
symbol = "🡅"
elif price < last_price:
trend = -1
symbol = "🡇"
display.triangle(draw, 0, 0, trend, width=16, height=32)
#display.triangle(draw, 0, 0, trend, width=16, height=32)
print(symbol)
text = f"BTC: {price:.0f}"
text = f"{symbol} BTC: {price:.0f}"
draw.text((20, 0), text, fill=(255, 255, 255), font=display.font)
draw.text((20, 0), text, fill=(255, 255, 255), font=lib.display.matrix.large_font)
display.do(image_buffer)
lib.display.matrix.show(image_buffer)
last_price = price
# Alle 10 Sekunden einen neuen Kurs holen. Jede Sekunde auf "stop" horchen.
@ -45,3 +52,4 @@ def start(image_buffer, stop_event, text="Hello World!"):
return
time.sleep(1)

View file

@ -9,7 +9,7 @@ import datetime
import locale
locale.setlocale(locale.LC_TIME, "de_DE.UTF-8")
def start(stop_event, text="Hello World!"):
def start(stop_event, args):
image_buffer = lib.display.matrix.buffer()
draw = ImageDraw.Draw(image_buffer)
while not stop_event.is_set():

31
scenes/color.py Normal file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env python3
import io
from time import sleep
from PIL import Image, ImageDraw, ImageFont
import lib.display
import datetime
import locale
locale.setlocale(locale.LC_TIME, "de_DE.UTF-8")
def start(stop_event, args):
image_buffer = lib.display.matrix.buffer()
draw = ImageDraw.Draw(image_buffer)
#print(int(args.get('red', 0)))
# All to color
draw.rectangle(
( (0,0), (lib.display.matrix.width-1,lib.display.matrix.height-1) ),
fill=(
int(args.get('red', 0)),
int(args.get('green', 0)),
int(args.get('blue', 0))
)
)
lib.display.matrix.show(image_buffer)
while not stop_event.is_set():
sleep(0.5)

View file

@ -9,7 +9,7 @@ import datetime
import locale
locale.setlocale(locale.LC_TIME, "de_DE.UTF-8")
def start(stop_event, text="Hello World!"):
def start(stop_event, args):
while not stop_event.is_set():
image_buffer = lib.display.matrix.buffer()
draw = ImageDraw.Draw(image_buffer)