"hue": light_color, "sat": 255, "on": True, "bri": 255, } res = s.put(api_url + 'lights/{}/state'.format(light_id), data=json.dumps(body)) # pprint(res.json()) time.sleep(1) time.sleep(1) s = requests.Session() s.headers = {} # make our packet smaller. The server ignores headers #hue_url = 'http://169.254.159.24/' hue_url = discover.find_hue() if len(sys.argv) > 1: # oh boy, adding options. rewrite this after the talk... current_guess = sys.argv[1] else: current_guess = users.USERNAME_PREFIX count = -1 # hack to parse data first. This lets us restart the process. Sorta start_time = time.time() interval = start_time username_generators = [] def make_username_generators(current_guess): results = []
#!/usr/bin/env python import json import random from pprint import pprint import requests import users import discover hue_url = discover.find_hue() request_dict = { "devicetype": "timinguser", "username": users.generate_username().next(), } res = requests.post(hue_url + 'api', headers={'Content-Type': 'text/plain'}, data=json.dumps(request_dict)) print res.json() for message in res.json(): if message.get('error'): raise Exception(message['error']['description']) if message.get('success'): username = message['success']['username'] with open('username', 'w') as f: f.write(username) res = requests.get(hue_url + 'api/{}/config'.format(username)).json() for user in res['whitelist'].keys(): if user != username: res = requests.delete(hue_url + 'api/{}/config/whitelist/{}'.format(