2015-03-01 17:29:34 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2015-03-08 20:25:38 +01:00
|
|
|
try:
|
|
|
|
import Image
|
|
|
|
import ImageDraw
|
|
|
|
HAVE_PIL = True
|
|
|
|
except:
|
|
|
|
try:
|
|
|
|
from PIL import Image
|
|
|
|
from PIL import ImageDraw
|
|
|
|
HAVE_PIL = True
|
|
|
|
except:
|
|
|
|
HAVE_PIL = False
|
|
|
|
|
2015-03-08 19:48:30 +01:00
|
|
|
import time
|
|
|
|
|
2015-03-08 20:05:04 +01:00
|
|
|
from rgbmatrix import Adafruit_RGBmatrix
|
|
|
|
|
2015-03-01 17:29:34 +01:00
|
|
|
import requests
|
|
|
|
import json
|
|
|
|
|
2015-03-08 20:05:04 +01:00
|
|
|
# Rows and chain length are both required parameters:
|
|
|
|
matrix = Adafruit_RGBmatrix(32, 3)
|
|
|
|
|
2015-03-01 17:29:34 +01:00
|
|
|
r = requests.get('https://spaceapi.syn2cat.lu/status/json')
|
|
|
|
|
|
|
|
obj = json.loads(r.text)
|
|
|
|
|
2015-03-08 20:05:04 +01:00
|
|
|
def main():
|
|
|
|
|
|
|
|
presence = obj["sensors"]["people_now_present"][0]["value"]
|
|
|
|
|
|
|
|
|
|
|
|
if obj["state"]["open"]:
|
|
|
|
print("And we are open!")
|
|
|
|
print("There are {} Hackers present NOW!".format(presence))
|
|
|
|
openSpace()
|
|
|
|
|
|
|
|
if obj["state"]["closed"]:
|
|
|
|
print("And we are closed!")
|
|
|
|
print("There were {} Hackers present! Good night, good fight!".format(presence))
|
|
|
|
closedSpace()
|
|
|
|
|
|
|
|
|
|
|
|
def openSpace():
|
|
|
|
matrix.Clear()
|
|
|
|
image = Image.open("images/32px-LightOn.svg.png")
|
|
|
|
image.load()
|
|
|
|
for n in range(32, -image.size[0], -1):
|
|
|
|
matrix.SetImage(image.im.id, n, 1)
|
|
|
|
time.sleep(0.025)
|
|
|
|
|
|
|
|
def closedSpace():
|
|
|
|
matrix.Clear()
|
|
|
|
image = Image.open("images/32px-LightOf.svg.png")
|
|
|
|
image.load()
|
|
|
|
for n in range(32, -image.size[0], -1):
|
|
|
|
matrix.SetImage(image.im.id, n, 1)
|
|
|
|
time.sleep(0.025)
|
2015-03-01 17:29:34 +01:00
|
|
|
|
|
|
|
|
2015-03-08 20:06:40 +01:00
|
|
|
if __name__ == "__main__": main()
|