dom/main.py

33 lines
1.3 KiB
Python
Raw Permalink Normal View History

2024-02-23 20:24:59 +05:00
import requests
import time
from datetime import datetime
def main():
while True:
current_time = datetime.now().strftime("%H:%M")
if "21:00" <= current_time < "09:00":
url = "http://192.168.89.21/api/radio?receive=3&comand_id=9&comand=2&metrika=0"
elif "09:00" <= current_time < "21:00":
url = "http://192.168.89.21/api/radio?receive=3&comand_id=9&comand=1&metrika=0"
else:
# If the current time doesn't fall within the defined ranges, sleep for a minute and then check again
time.sleep(60)
continue
try:
response = requests.get(url)
if response.status_code == 200:
print(f"Результат запроса ({current_time}):", response.text)
else:
print(f"Ошибка при запросе ({current_time}). Код состояния:", response.status_code)
except requests.RequestException as e:
print(f"Ошибка при выполнении запроса ({current_time}):", e)
# После выполнения запроса ожидаем минуту перед повторной проверкой времени
time.sleep(60)
if __name__ == "__main__":
main()