Deutsch

Почему не работает этот код в Питоне

03.09.23 19:04
Re: Почему не работает этот код в Питоне
 
kukka местный житель
kukka
в ответ uscheswoi_82 02.09.23 23:22, Последний раз изменено 03.09.23 20:17 (kukka)
  1. import requests
  2. from datetime import datetime
  3. MY_LAT = 38.548330
  4. MY_LONG = -90.326280
  5. LOCAL_UTC_OFFSET = 6
  6. #response = requests.get(url="http://api.open-notify.org/iss-now.json")
  7. #response.raise_for_status()
  8. #data= response.json()
  9. #longitude = data["iss_position"]["longitude"]
  10. #latitude = data["iss_position"][latitude]
  11. #iss_position = (longiture, latitude)
  12. #print(iss_position)
  13. def utc_to_local(utc_hour):
  14. utc_hour += LOCAL_UTC_OFFSET
  15. if LOCAL_UTC_OFFSET > 0:
  16. if utc_hour > 23:
  17. utc_hour -= 24
  18. elif LOCAL_UTC_OFFSET < 0:
  19. if utc_hour < 0:
  20. utc_hour += 24
  21. return utc_hour
  22. parameters = {
  23. "lat": MY_LAT,
  24. "lng": MY_LONG,
  25. "formatted": 0,
  26. }
  27. response = requests.get("https://api.sunrise-sunset.org/json", params=parameters)
  28. response.raise_for_status()
  29. data = response.json()
  30. sunrise = int(data["results"]["sunrise"].split("T")[1].split(":")[0])
  31. sunset = int(data["results"]["sunset"].split("T")[1].split(":")[0])
  32. lt_sunrise = utc_to_local(sunrise)
  33. lt_sunset = utc_to_local(sunset)
  34. print(sunrise)
  35. print(sunset)
  36. time_now = datetime.now()
  37. print(time_now.hour)


Спасибо за советы, читаю другие форумы.

 

Перейти на