led-matrix-panel/scenes/bitcoin.py
2026-01-11 16:20:31 +01:00

47 lines
1.2 KiB
Python

#!/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)