From b455762fa20af256019440e420831946f8fab374 Mon Sep 17 00:00:00 2001 From: mischa Date: Fri, 27 Dec 2019 15:43:37 +0100 Subject: [PATCH] added script to create new developer, clip.html wasn't working --- add-newdeveloper.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 add-newdeveloper.py diff --git a/add-newdeveloper.py b/add-newdeveloper.py new file mode 100755 index 0000000..6377fc0 --- /dev/null +++ b/add-newdeveloper.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +# +# Copyright 2019, Mischa Peters , High5!. +# Version 1.0 - 20191227 +# +# Create a new user on the bridge +# +# For example: +# $ create-new.py +# +# Follow the steps at the Hue Developer site to get the username/token +# https://developers.meethue.com/develop/get-started-2/ +# +# Requires: +# - Python >3.6 +# +import argparse +import ssl +import urllib.request +import json + +parser = argparse.ArgumentParser(description="Control light") +parser.add_argument("bridge", type=str, help="Hue Bridge IP") + +try: + args = parser.parse_args() + bridge = args.bridge + +except argparse.ArgumentError as e: + print(str(e)) + +no_cert_check = ssl.create_default_context() +no_cert_check.check_hostname=False +no_cert_check.verify_mode=ssl.CERT_NONE + +data = b'{"devicetype": "my_hue_app#device"}' +url = f"https://{bridge}/api" +req = urllib.request.Request(url=url, data=data, method='POST') +with urllib.request.urlopen(req, context=no_cert_check) as response: + content = response.read() +json_data = json.loads(content) +print (f"{json_data}")