Advertisement
teslariu

api openweather

May 30th, 2023
932
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import requests
  5. from datetime import datetime
  6. from pprint import pprint
  7.  
  8. lat = -34.61
  9. lon = -58.38
  10. API_key = "6ce13bc6d5a965e991adaea8fce8676a"
  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.  
  15. # Pronóstico crudo
  16. datos = r.json()
  17. pprint(datos)
  18.  
  19. print(f"Fecha y hora del pronóstico: {datetime.fromtimestamp(datos['dt'])}")
  20. print(f"Salida del Sol: {datetime.fromtimestamp(datos['sys']['sunrise'])}")
  21. print(f"Puesta del Sol: {datetime.fromtimestamp(datos['sys']['sunset'])}")
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement