parent
7afb5b55b3
commit
4e73b14ab1
@ -1,2 +1,3 @@ |
|||||||
config.py |
config.py |
||||||
lib/__pycache__/ |
lib/__pycache__/ |
||||||
|
__pycache__/ |
||||||
|
@ -1,15 +1,20 @@ |
|||||||
import requests as req # Used for HTTP requests for the Hue API |
import requests as req # Used for HTTP requests for the Hue API |
||||||
import json # API uses JSON |
import json # API uses JSON |
||||||
import config # Configuration for the controller |
import config # Configuration for the controller (/config.py <- change this file) |
||||||
|
|
||||||
def genUrl(params: str): |
def genUrl(params: str): |
||||||
return "https://" + config.address + "/api/" + config.username + params |
return "http://" + config.address + "/api/" + config.username + params |
||||||
|
|
||||||
def API_Request(ReqType: str, params: str): |
await def API_Request(ReqType: str="GET", params: str=""): # Requests for the API |
||||||
apiReq = req.Request( ReqType, genUrl(params) ) |
try: |
||||||
|
apiReq = req.Request( ReqType, genUrl(params) ) |
||||||
|
apiReqPrep = apiReq.prepare() |
||||||
|
|
||||||
apiReqPrep = apiReq.prepare() |
apiSession = req.Session() |
||||||
apiSession = req.Session() |
response = apiSession.send(apiReqPrep) |
||||||
apiSession.send(apiReqPrep) |
|
||||||
|
print(response.body) |
||||||
|
except req.exceptions.RequestException as err: |
||||||
|
raise SystemExit(err) # throw the error |
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,19 @@ |
|||||||
#!/usr/bin/env python |
#!/usr/bin/env python |
||||||
from lib.input import * # Commandline parser |
from lib.input import * # Commandline parser |
||||||
|
|
||||||
import hue_controller # Actual controller |
import hue_controller as hue # Actual controller |
||||||
|
|
||||||
def init(): |
params = "" |
||||||
|
if( inputHasKeys(["-p"]) ): |
||||||
|
params = getValueOfKey("-p") |
||||||
|
|
||||||
|
reqtype = "GET" |
||||||
|
if( inputHasKeys(["-t"]) ): |
||||||
|
reqtype = getValueOfKey("-t") |
||||||
|
|
||||||
|
|
||||||
|
def init(): |
||||||
|
print(reqtype, params) |
||||||
|
hue.API_Request(reqtype, params) |
||||||
|
|
||||||
init() |
init() |
||||||
|
Loading…
Reference in new issue