Skip to content

Commit a1035ca

Browse files
Create bitcoin.py
1 parent c703275 commit a1035ca

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

bitcoin.py

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#! /usr/bin/env python
2+
3+
from __future__ import print_function
4+
import subprocess
5+
import sys
6+
import time
7+
import json, requests
8+
import math
9+
import scrollphat
10+
11+
12+
scrollphat.set_brightness(4)
13+
14+
# Every refresh_interval seconds we'll refresh the weather data, doesn't change too often so 30mins appropriate
15+
pause = 0.12
16+
ticks_per_second = 1/pause
17+
refresh_interval = 60
18+
19+
url = "http://api.coindesk.com/v1/bpi/currentprice.json"
20+
21+
def get_timeout():
22+
return ticks_per_second * refresh_interval
23+
24+
def get_wet():
25+
# Get the weather data
26+
# print("Price Update...")
27+
#scrollphat.set_pixels(lambda x, y: 1, auto_update=True)
28+
resp = requests.get(url)
29+
sine()
30+
try:
31+
data = json.loads(resp.text)
32+
except:
33+
print(resp)
34+
return "ERR"
35+
val = data['bpi']['USD']['rate']+" "
36+
return val
37+
38+
def sine():
39+
timer = 0
40+
i = 0
41+
buf = [0] * 11
42+
while (timer < 2):
43+
try:
44+
for x in range(0, 11):
45+
y = (math.sin((i + (x * 10)) / 10.0) + 1) # Produces range from 0 to 2
46+
y *= 2.5 # Scale to 0 to 5
47+
buf[x] = 1 << int(y)
48+
49+
scrollphat.set_buffer(buf)
50+
scrollphat.update()
51+
52+
time.sleep(0.005)
53+
timer+=0.005
54+
i += 1
55+
except KeyboardInterrupt:
56+
scrollphat.clear()
57+
sys.exit(-1)
58+
59+
timeout = get_timeout()
60+
count = 0
61+
msg = get_wet()
62+
scrollphat.write_string(msg)
63+
64+
while True:
65+
try:
66+
# scrollphat.scroll()
67+
time.sleep(pause)
68+
69+
if(count > timeout):
70+
msg = get_wet()
71+
scrollphat.write_string(msg)
72+
timeout = get_timeout()
73+
count = 0
74+
else:
75+
count = count+ 1
76+
except KeyboardInterrupt:
77+
scrollphat.clear()
78+
sys.exit(-1)
79+

0 commit comments

Comments
 (0)