-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo_text_on_matrix.py
92 lines (75 loc) · 3.17 KB
/
demo_text_on_matrix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2017-18 Richard Hull and contributors
# See LICENSE.rst for details.
import os
import time
import argparse
from datetime import date
import json
import requests
from luma.led_matrix.device import max7219
from luma.core.interface.serial import spi, noop
from luma.core.render import canvas
from luma.core.legacy import text
from luma.core.legacy import text, show_message
from luma.core.legacy.font import proportional, CP437_FONT, TINY_FONT, SINCLAIR_FONT, LCD_FONT
from qlient.http import HTTPClient, GraphQLResponse
def startFeed():
# create matrix device
serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial, width=32, height=8, rotate=0, block_orientation=-90)
print("Created device")
print("Showing rectangle")
with canvas(device) as draw:
draw.rectangle(device.bounding_box, outline="white")
try:
while(True):
print("Parsing ethermine-api")
#url = "https://api.ethermine.org/miner/a4aBfc14202339cd55BFB94BD23cf07301443C24/currentStats"
#r = requests.get(url)
#print(r.json()["data"])
#usdPerMin = float(r.json()["data"]["usdPerMin"])
#print("usdPerMin: ",usdPerMin)
#print("Parsing ethermine-api - DONE")
#print("Parsing CurrencyConverter-api")
#sekPerMin = float(c.convert(usdPerMin, 'USD', 'SEK'))
#print("Parsing CurrencyConverter-api - DONE")
#sekPerDay = round(sekPerMin*60*24,2)
#print("sekPerDay: ", sekPerDay)
client = HTTPClient("https://swapi-graphql.netlify.app/.netlify/functions/index")
res: GraphQLResponse = client.query.film(
# swapi graphql input fields
id="ZmlsbXM6MQ==",
# qlient specific
_fields=["id", "title", "episodeID"]
)
print(res.request.query) # query film($id: ID) { film(id: $id) { id title episodeID } }
print(res.request.variables) # {'id': 'ZmlsbXM6MQ=='}
printMessage = res.data.film.id
with canvas(device) as draw:
#draw.rectangle(device.bounding_box, outline="white")
text(draw, (0, 1), printMessage, fill="white", font=proportional(CP437_FONT))
#text(draw, (0, 1), "73.93", fill="white", font=proportional(LCD_FONT))
print("Sleep for 120 sec")
time.sleep(120)
print("Parse again!")
except KeyboardInterrupt:
print("Exiting program!")
pass
except:
print("Failed to parse, trying again.")
startFeed()
pass
#while(True):
#d = datetime()
#show_message(device, "193 mh/s", fill="white", font=proportional(LCD_FONT),scroll_delay=0.05)
#show_message(device, "76.5 sek", fill="white", font=proportional(LCD_FONT),scroll_delay=0.05)
#show_message(device, "1 Eth = 954 $", fill="white", font=proportional(LCD_FONT),scroll_delay=0.05)
if __name__ == "__main__":
try:
print("-> Starting program <-")
startFeed()
except:
print("ERROR!")
pass