Created
March 8, 2016 09:53
-
-
Save jamesbowles/a0318b14d201caab2411 to your computer and use it in GitHub Desktop.
This file contains 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
import bluetooth | |
import time | |
import urllib2 | |
import json | |
while True: | |
hour = time.localtime().tm_hour | |
if (hour < 17): | |
print "it's too early for this" | |
else: | |
print "looking for James" | |
result = bluetooth.lookup_name('XX:XX:XX:XX:XX:XX', timeout=5) | |
if (result != None): | |
print "found James!" | |
print "checking the lights" | |
data = urllib2.urlopen("http://192.168.1.2/cgi-bin/json.cgi?get=state").read() | |
data.strip() | |
output = json.loads(data[1:-2]) | |
if (output["state"] == "off"): | |
print "turning the light on!" | |
data = urllib2.urlopen("http://192.168.1.2/cgi-bin/json.cgi?set=on").read() | |
print data | |
time.sleep(1) | |
else: | |
print "the lights are already on" | |
time.sleep(5) | |
time.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment