-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
54 lines (41 loc) · 918 Bytes
/
server.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import time
import schedule
from sense_hat import SenseHat
from app.pixels import GeneratePixels
from app.utilities.format import item
from app.fetch import FetchCitiBikeData, ExtractStationData
def Main():
'''Wrapper.'''
#
# Collect data.
#
data = FetchCitiBikeData()
station = ExtractStationData(data=data,id=445)
#
# Generate pixels.
#
pixels = GeneratePixels(station['data']['availableBikes'])
#
# Send to SenseHAT.
#
sense = SenseHat()
sense.set_pixels(pixels)
#
# Starting schedule.
#
schedule.every(30).seconds.do(Main)
def Main(verbose=True):
'''Wrapper to run all the scheduled tasks.'''
if verbose:
print '%s Running scheduler.' % item('prompt_bullet')
try:
while True:
schedule.run_pending()
time.sleep(1)
except Exception as e:
print e
return False
if __name__ == '__main__':
Main()