'Better way to make successive requests in python
I have a python program who's always need to be up to date in an API that I create. For now I just make a request every 1 seconds, but I wonder if there is a more simple way to do that (without make a request every 1 seconds).
To resume my program, I have an API with data on my house (state of the shutters, temperature, automatic watering...) and if some data change I update some wifi devices.
Here is a structure of my program :
while True:
try:
data = requests.get(url, dataQuery)
except Exception as e:
isData = False
print('error')
if isData:
if data.temperature >= 24:
# enabled device temperature
if data.shutter1 == "on":
# enabled device shutter 1
time.sleep(1)
Thank for all your responses !
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
