Skip to content

Instantly share code, notes, and snippets.

@glynrob
Created July 28, 2012 20:18
Show Gist options
  • Save glynrob/3194646 to your computer and use it in GitHub Desktop.
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
#!/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