-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOmega_Matrix_Display.py
41 lines (30 loc) · 1.08 KB
/
Omega_Matrix_Display.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
# This is for writing to matrix display through Arduino dock
import serial
import datetime
import pytz
import urllib.request
import json
dock = serial.Serial(port='/dev/ttyS1', baudrate=57600)
dock.write(str.encode("Running\0"))
now = datetime.datetime.now(pytz.timezone('US/Eastern'))
dateString = now.strftime('%a %b %d, %Y')
dock.write(str.encode(dateString + ' | '))
try:
url = "https://api.blockchain.info/stats"
response = urllib.request.urlopen(url)
data = json.loads(response.read())
st = "BTC = $%(number).2f | " % {"number" : data['market_price_usd']}
dock.write(str.encode(st))
# Batavia, OH 39.1060,-84.2411 ILN Grid points 44, 38
url = "https://api.weather.gov/gridpoints/ILN/44,38/forecast"
response = urllib.request.urlopen(url)
data = json.loads(response.read())
summary = data['properties']['periods'][0]
string = summary['name'] + ': ' + summary['detailedForecast']
dock.write(str.encode(string))
except:
# Maybe no internet connection?
dock.write(str.encode("Internet not available"))
finally:
dock.write(str.encode("\0"))
dock.close()