Advertisement
teslariu

api

Jul 13th, 2021
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 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. url = "https://api.openweathermap.org/data/2.5/weather?q=Buenos%20Aires,AR&units=metric&lang=es&appid=6ce13bc6d5a965e991adaea8fce8676a"
  9. r = requests.get(url)
  10. datos = r.json()
  11. pprint(datos)
  12.  
  13. # muestro la hora del pronòstico (timestamp)
  14. horario = datetime.fromtimestamp(datos['dt'])
  15. print(f"Hora del pronostico: {horario}")
  16.  
  17. # muestro el horario de la salida del sol
  18. amanecer = datetime.fromtimestamp(datos['sys']['sunrise'])
  19. print(f"Amanecer: {amanecer}")
  20.  
  21. # muestro el horario del ocaso
  22. ocaso = datetime.fromtimestamp(datos['sys']['sunset'])
  23. print(f"Ocaso: {ocaso}")
  24.  
  25. print("------------------------------------------------")
  26.  
  27.  
  28. url2 = "https://api.openweathermap.org/data/2.5/onecall?lat=-34.61&lon=-58.38&units=metric&lang=es&appid=6ce13bc6d5a965e991adaea8fce8676a"
  29. r = requests.get(url2)
  30. datos = r.json()
  31. pprint(datos)
  32.  
  33. print("---------------")
  34.  
  35. print(datos)
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement