many works

This commit is contained in:
Christoph Haas 2026-01-11 16:20:31 +01:00
parent 9bd764579a
commit c937450f92
7 changed files with 151 additions and 36 deletions

47
scenes/bitcoin.py Normal file
View file

@ -0,0 +1,47 @@
#!/usr/bin/env python3
import time
from PIL import Image, ImageDraw
from lib import display
# Replace with your free Finnhub API key
API_KEY = "d3t8099r01qigeg1s7cgd3t8099r01qigeg1s7d0"
import finnhub
finnhub_client = finnhub.Client(api_key="d3t8099r01qigeg1s7cgd3t8099r01qigeg1s7d0")
def get_bitcoin_price():
symbol = "BINANCE:BTCEUR"
data = finnhub_client.quote(symbol)
return data['c']
def start(image_buffer, stop_event, text="Hello World!"):
last_price = None
trend = None
while not stop_event.is_set():
image_buffer = Image.new("RGB", (128, 64))
draw = ImageDraw.Draw(image_buffer)
price = get_bitcoin_price()
# Trend berechnen
if last_price:
if price > last_price:
trend = 1
elif price < last_price:
trend = -1
display.triangle(draw, 0, 0, trend, width=16, height=32)
text = f"BTC: {price:.0f}"
draw.text((20, 0), text, fill=(255, 255, 255), font=display.font)
display.do(image_buffer)
last_price = price
# Alle 10 Sekunden einen neuen Kurs holen. Jede Sekunde auf "stop" horchen.
for i in range(1,10):
if stop_event.is_set():
return
time.sleep(1)

View file

@ -3,29 +3,21 @@
import io
from time import sleep
from PIL import Image, ImageDraw, ImageFont
from lib import display
#from lib import display
import lib.display
# TODO: Derive from number of panels and panel size
matrix_height = 64
matrix_width = 64 * 2
# Load a font (use a TTF font file of your choice)
try:
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 12)
except IOError:
font = ImageFont.load_default()
def start(image_buffer, stop_event, text="Hello World!"):
def start(stop_event, text="Hello World!"):
t = 0
while not stop_event.is_set():
image_buffer = Image.new("RGB", (128, 64))
#image_buffer = Image.new("RGB", (lib.display.matrix_width, lib.display.matrix_height))
image_buffer = lib.display.matrix.buffer()
draw = ImageDraw.Draw(image_buffer)
draw.text((0, 0), f"Hello World {t}", fill=(255, 255, 255), font=font)
draw.text((0, 0), f"Hello World {t}", fill=(255, 255, 255), font=lib.display.matrix.font)
t += 1
print(t)
#image_buffer.save('image.png')
display.do(image_buffer)
lib.display.matrix.show(image_buffer)
#sleep(0.2)
sleep(0.2)