led-matrix-panel/scenes/bitcoin.py
2026-01-17 00:02:17 +01:00

56 lines
1.4 KiB
Python

#!/usr/bin/env python3
import time
from PIL import Image, ImageDraw
import lib.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)
#print("getting finnhub")
return data['c']
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():
# 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()
# Trend berechnen
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)
#print(symbol)
#text = f"{symbol} BTC: {price:.0f}€"
text = f"BTC: {price:.0f}"
draw.text((20, 0), text, fill=(255, 255, 255), font=lib.display.matrix.large_font)
lib.display.matrix.show(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)