Advertisement
teslariu

api openweather

Jul 13th, 2023
1,235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import requests
  2. from datetime import datetime
  3. from pprint import pprint
  4.  
  5. API_key = "6ce13bc6d5a965e991adaea8fce8676a"
  6. lat = -34.61
  7. lon = -58.38
  8. # Prnostico a 5 días
  9. # url = f"https://api.openweathermap.org/data/2.5/forecast?lat={lat}&lon={lon}&units=metric&lang=es&appid={API_key}"
  10.  
  11.  
  12. url = f"https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&units=metric&lang=es&appid={API_key}"
  13. r = requests.get(url)
  14. datos = r.json()
  15. pprint(datos)
  16.  
  17. print()
  18.  
  19. print(f"Hora actual: {datetime.fromtimestamp(datos['dt'])}")
  20. print(f"Temperatura: {datos['main']['temp']:.1f}ºC")
  21. print(f"Sensación térmica: {datos['main']['feels_like']:.1f}ºC")
  22.  
  23. print(f"Salida del Sol: {datetime.fromtimestamp(datos['sys']['sunrise'])}")
  24. print(f"Puesta del Sol: {datetime.fromtimestamp(datos['sys']['sunset'])}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement