Created
July 28, 2012 20:18
-
-
Save glynrob/3194646 to your computer and use it in GitHub Desktop.
Checks an API and sends the a returning colour dependant on the result
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import subprocess | |
import time | |
import urllib | |
import usblamp | |
import signal | |
import sys | |
def signal_handler(signal, frame): | |
print 'Code exited' | |
usblamp.switchTo("off") | |
sys.exit(0) | |
signal.signal(signal.SIGINT, signal_handler) | |
print 'Started... Press Ctrl+C to exit' | |
checkTime = 4 | |
while True: | |
status = urllib.urlopen('http://glynrob.com/api/rand3.php').read() | |
if status == '0': | |
usblamp.switchTo("green") | |
elif status == '1': | |
usblamp.switchTo("yellow") | |
else: | |
usblamp.switchTo("red") | |
print status | |
time.sleep(checkTime) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment