Advertisement
teslariu

openweather

Sep 20th, 2021
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 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. # current weather data
  9. url = "https://api.openweathermap.org/data/2.5/weather?q=Buenos%20Aires&units=metric&lang=es&appid=6ce13bc6d5a965e991adaea8fce8676a"
  10. r = requests.get(url)
  11. data = r.json()
  12. pprint(data)
  13. print("Fecha y hora:")
  14. print(datetime.fromtimestamp(data['dt']))
  15.  
  16. print("Salida del Sol:")
  17. print(datetime.fromtimestamp(data['sys']['sunrise']))
  18. print("Puesta del Sol:")
  19. print(datetime.fromtimestamp(data['sys']['sunset']))
  20.  
  21. # one call API
  22. url = 'https://api.openweathermap.org/data/2.5/onecall?lat=-34.61&lon=-58.38&units=metric&lang=es&exclude={current,minutely,hourly}&appid=6ce13bc6d5a965e991adaea8fce8676a'
  23. r = requests.get(url)
  24. data = r.json()
  25. pprint(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement