Async requests

fetchIP
E. Almqvist 4 years ago
parent 7afb5b55b3
commit 4e73b14ab1
  1. 1
      .gitignore
  2. 15
      hue_controller.py
  3. 14
      main.py

1
.gitignore vendored

@ -1,2 +1,3 @@
config.py
lib/__pycache__/
__pycache__/

@ -1,15 +1,20 @@
import requests as req # Used for HTTP requests for the Hue API
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):
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
try:
apiReq = req.Request( ReqType, genUrl(params) )
apiReqPrep = apiReq.prepare()
apiSession = req.Session()
apiSession.send(apiReqPrep)
response = 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
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()

Loading…
Cancel
Save