I know you can shorten down the length of this python api call to hue using a variable but I cant figure out the format or the proper term to find the answer in stackoverflow. I would like to learn how to hide the auth token to practice better security and add a variable for multiple lights that i may add in the future. I believe i would need multiple variables within the URL. Please any help would be greatly appreciated.
import requests
url = "http://192.168.98.233/api/Cjk7782cABRgUggxUTlt8DwwnK516ilhMHzHwFlq/lights/{}/state".format(1)
url2= "http://192.168.98.233/api/Cjk7782cABRgUggxUTlt8DwwnK516ilhMHzHwFlq/lights/{}/state".format(2)
url3= "http://192.168.98.233/api/Cjk7782cABRgUggxUTlt8DwwnK516ilhMHzHwFlq/lights/{}/state".format(3)
payload = " {\"on\":false}"
headers = {
'content-type': "application/json",
'cache-control': "no-cache"
}
r = requests.put(url, data=payload, headers=headers)
r2 = requests.put(url2, data=payload, headers=headers)
r3 = requests.put(url3, data=payload, headers=headers)
print(r.text)
print(r2.text)
print(r3.text)