Advertisement
teslariu

api clima

Oct 28th, 2023
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 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. API_key = "db7ba55a8af3d8d738d88349a7c9380d"
  9. url = f"https://api.openweathermap.org/data/2.5/weather?lat=-34.61&lon=-58.38&units=metric&lang=es&appid={API_key}"
  10.  
  11. r = requests.get(url)
  12. data = r.json()
  13.  
  14. print(f"Fecha y hora del pronóstico: {datetime.fromtimestamp(data['dt'])}")
  15. print(f"Salida del sol: {datetime.fromtimestamp(data['sys']['sunrise'])}")
  16. print(f"Puesta del Sol:{datetime.fromtimestamp(data['sys']['sunset'])}")
  17. print(f"Humedad: {data['main']['humidity']}%")
  18.  
  19. pprint(data)
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement