-
Notifications
You must be signed in to change notification settings - Fork 1
/
whereis.py
83 lines (63 loc) · 1.86 KB
/
whereis.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
#!/usr/bin/env python
##
# whereis.py
##
# This script updates a Waveshare 2.13inch three-colour e-Paper HAT
# with status information taken from BBC Whereabouts.
#
# Author: Libby Miller <[email protected]>
# Author: Henry Cooke <[email protected]>
#
##
import epd2in13b
import time
import Image
import ImageDraw
import ImageFont
import json
COLORED = 1
UNCOLORED = 0
try:
import requests
except ImportError:
exit("This script requires the requests module\nInstall with: sudo pip install requests")
def get_location( user_number, auth_token ):
url = 'https://where.virt.ch.bbc.co.uk/api/1/users/%s/location.json?auth_token=%s' % (
user_number,
auth_token
)
res = requests.get(url)
if(res.status_code == 200):
json_data = json.loads(res.text)
return json_data
return {}
def load_config():
lines = []
with open( "config.txt" ) as f:
lines = f.read().splitlines()
return {
"caption" : lines[0],
"user_number" : lines[1],
"auth_token" : lines[2],
}
def main():
config = load_config()
epd = epd2in13b.EPD()
epd.init()
epd.set_rotate(1)
# clear the frame buffer
frame_black = [0xFF] * (epd.width * epd.height / 8)
frame_red = [0xFF] * (epd.width * epd.height / 8)
epd.draw_filled_rectangle(frame_red, 0, 0, 250, 55, COLORED);
font = ImageFont.truetype('/usr/share/fonts/AmaticSC-Bold.ttf', 38)
epd.draw_string_at(frame_red, 25, 10, config["caption"], font, UNCOLORED)
data = get_location( config["user_number"], config["auth_token"] )
ds = "unknown"
print(data)
if(u'description' in data):
print(data["description"])
ds = data["description"]
epd.draw_string_at(frame_black, 25, 60, ds, font, COLORED)
epd.display_frame(frame_black, frame_red)
if __name__ == '__main__':
main()