teslariu

openweather

Jun 2nd, 2023
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import requests
  4.  
  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.  
  14. r = requests.get(url)
  15.  
  16. data = r.json()
  17. pprint(data)
  18.  
  19. print(f"\nPronostico principal")
  20. pprint(data['main'])
  21.  
  22. print()
  23. print(f"Salida del sol: {datetime.fromtimestamp(data['sys']['sunrise'])}")
  24. print(f"Puesta del sol: {datetime.fromtimestamp(data['sys']['sunset'])}")
Advertisement
Add Comment
Please, Sign In to add comment