- updated main

master
Steve Clement 2016-06-11 21:38:30 +02:00
parent 2fbe14e9c6
commit eb77b68951
2 changed files with 38 additions and 9 deletions

View File

@ -1,9 +1,11 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
import json import json
import urllib.request as ur import urllib.request as ur
import urllib.parse as par import urllib.parse as par
import datetime from datetime import timedelta, datetime
import time import time
url = "https://level2.lu/spaceapi/" url = "https://level2.lu/spaceapi/"
@ -14,18 +16,29 @@ data = json.loads(xml.decode('utf-8'))
stateOpen = data['state']['open'] stateOpen = data['state']['open']
stateLast = data['state']['lastchange'] stateLast = data['state']['lastchange']
now = int(time.time()) now = time.time()
print("Last triggered: " + str((now - stateLast))) def getTime(seconds):
sec = timedelta(seconds=int(seconds))
d = datetime(1,1,1) + sec
print(stateLast) if d.day-1 > 0:
return("{} day(s), {} hour(s), {} minute(s) and {} seconds".format(d.day-1, d.hour, d.minute, d.second))
elif d.hour > 0:
return("{} hour(s), {} minute(s) and {} seconds".format(d.hour, d.minute, d.second))
elif d.minute > 0:
return("{} minute(s) and {} seconds".format(d.minute, d.second))
else:
return("{} seconds".format(d.second))
st = getTime(now- stateLast)
print("Last triggered: " + st)
if stateOpen == True: if stateOpen == True:
print("Space is open!") print("Space is open!")
countPeople = data['sensors']['people_now_present']
print("We are " + str(countPeople[0]['value'])) type(countPeople)
else: else:
print("We are closed :(") print("We are closed :(")
countPeople = data['sensors']['people_now_present']
type(countPeople)
print("We are " + str(countPeople[0]['value']))

18
main.py
View File

@ -1,4 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
try: try:
import Image import Image
@ -22,7 +24,9 @@ import json
# Rows and chain length are both required parameters: # Rows and chain length are both required parameters:
matrix = Adafruit_RGBmatrix(32, 3) matrix = Adafruit_RGBmatrix(32, 3)
r = requests.get('https://spaceapi.syn2cat.lu/status/json') spaceAPI = [ "https://level2.lu/spaceapi/", "https://spaceapi.syn2cat.lu/status/json" ]
r = requests.get(spaceAPI[0])
obj = json.loads(r.text) obj = json.loads(r.text)
@ -58,5 +62,17 @@ def closedSpace():
matrix.SetImage(image.im.id, n, 1) matrix.SetImage(image.im.id, n, 1)
time.sleep(0.025) time.sleep(0.025)
def getTime(seconds):
sec = timedelta(seconds=int(seconds))
d = datetime(1,1,1) + sec
if d.day-1 > 0:
return("{} day(s), {} hour(s), {} minute(s) and {} seconds".format(d.day-1, d.hour, d.minute, d.second))
elif d.hour > 0:
return("{} hour(s), {} minute(s) and {} seconds".format(d.hour, d.minute, d.second))
elif d.minute > 0:
return("{} minute(s) and {} seconds".format(d.minute, d.second))
else:
return("{} seconds".format(d.second))
if __name__ == "__main__": main() if __name__ == "__main__": main()