Jetzt hab ich einen BTC / ETH Price Ticker am Raspi am Schreibtisch und der Raspi stand da eh rum
Wen es interessiert
Hier der Link zu der Software für das Display und den Code kann ich gerne zur Verfügung stellen
https://www.amazon.de/gp/product/B07FYG8MZN
https://luma-oled.readthedocs.io/en/develop/python-usage.html
Datei: btc_ticker.py
# -*- coding: utf-8 -*-
# Copyright (c) 2017-2020 Michael Svanström, Richard Hull and contributors
# See LICENSE.rst for details.
# PYTHON_ARGCOMPLETE_OK
"""
Displays the Bitcoin price at Bitstamp
Example:
BTC/USD $2300.00
24h Hi $2400.00 Lo $2200.00
LTC/USD $40.00
24h Hi $50.00 Lo $30.00
"""
import sys
import time
from pathlib import Path
try:
import requests
except ImportError:
print("The requests library was not found. Run 'sudo -H pip install requests' to install it.")
sys.exit()
from demo_opts import get_device
from luma.core.render import canvas
from PIL import ImageFont
def fetch_price(crypto_currency, fiat_currency):
bitstamp_api = "https://www.bitstamp.net/api/v2/ticker/" + crypto_currency.lower() + fiat_currency.lower()
try:
r = requests.get(bitstamp_api)
return r.json()
except:
print("Error fetching from Bitstamp API")
def get_price_text(crypto_currency, fiat_currency):
data = fetch_price(crypto_currency, fiat_currency)
return [
'{}/{} {}'.format(crypto_currency, fiat_currency, data['last'])
]
def show_price(device):
# use custom font
oled_font1 = ImageFont.truetype('FreeSans.ttf', 20)
oled_font2 = ImageFont.truetype('FreeSans.ttf', 16)
with canvas(device) as draw:
draw.text((5, 0), "Crypto Ticker", font=oled_font1, fill = "white")
rows = get_price_text("BTC", "EUR")
draw.text((0, 25), rows[0], font=oled_font2, fill="white")
rows = get_price_text("ETH", "EUR")
draw.text((0, 45), rows[0], font=oled_font2, fill="white")
def main():
while True:
show_price(device)
time.sleep(60)
if __name__ == "__main__":
try:
device = get_device()
main()
except KeyboardInterrupt:
pass