-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
115 lines (101 loc) · 2.46 KB
/
main.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
### Author: Sam Machin
### License: MIT
### Appname: Schedule
### Description: Whats on Now and Next
import wifi
import ugfx
import pyb
import time
import buttons
from http_client import *
import json
import math
def showevent(stage, event):
start = event['start_date']
end = event['end_date']
speaker = event['speaker']
text = event['title']
ugfx.set_default_font(ugfx.FONT_MEDIUM)
ugfx.area(0,0,ugfx.width(),ugfx.height(),0x0000)
ugfx.text(10,10,stage,ugfx.GREY)
ugfx.text(10,35,"Start: "+start,ugfx.GREEN)
ugfx.text(10,60,"End: "+end,ugfx.RED)
ugfx.text(10,85,"Speaker: "+speaker,ugfx.BLUE)
linelen = 25
lines = int(math.ceil(len(text)/linelen))
for l in range(0, lines):
pixels = l*25+110
start = l*linelen
end = l*linelen+linelen
if end>len(text):
end = len(text)
linetext = text[start:end]
ugfx.text(10,pixels,linetext,0xFFFF)
return
def mainscreen():
ugfx.area(0,0,ugfx.width(),ugfx.height(),0x0000)
ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
ugfx.text(30,30,"EMF Schedule Now & Next ",ugfx.GREY)
ugfx.text(40,75,"Press [A] to get events ",ugfx.BLUE)
return
def getdata():
url = 'https://hackspace-leaderboard-scollins.c9users.io/leaderboard.json'
resp = get(url).text
return json.loads(resp)
def nownext():
ugfx.text(50,120,"Loading... ",ugfx.YELLOW)
data = getdata()
venue = list()
for i in data.keys():
venue.append(i)
venue = sorted(venue)
print(venue)
vpos = 0
hpos = 0
showevent(venue[vpos], data[venue[vpos]][hpos])
while True:
if buttons.is_triggered("JOY_RIGHT"):
print(vpos)
vpos += 1
if vpos > len(venue)-1:
vpos -= 1
else:
pass
showevent(venue[vpos], data[venue[vpos]][hpos])
if buttons.is_triggered("JOY_LEFT"):
print(vpos)
vpos -= 1
if vpos < 0:
vpos = 0
else:
pass
showevent(venue[vpos], data[venue[vpos]][hpos])
if buttons.is_triggered("JOY_DOWN"):
print(hpos)
hpos = 1
showevent(venue[vpos], data[venue[vpos]][hpos])
if buttons.is_triggered("JOY_UP"):
print(hpos)
hpos = 0
showevent(venue[vpos], data[venue[vpos]][hpos])
if buttons.is_triggered("BTN_A"):
# Need to Implement fetching description by ID here
pass
if buttons.is_triggered("BTN_B"):
mainscreen()
return
#Check and Connect to WiFi
if wifi.is_connected():
pass
else:
wifi.connect()
#Init GFX and Buttons
ugfx.init()
buttons.init()
#Main Screen
mainscreen()
while True:
if buttons.is_triggered('BTN_A'):
nownext()
if buttons.is_triggered('BTN_B'):
mainscreen()