Advertisement
teslariu

apis clima

Sep 13th, 2023
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # Hacer un script que muestra la cotización del dolar actualizada
  5. import requests
  6. from pprint import pprint
  7. from datetime import datetime
  8.  
  9.  
  10. '''
  11. url = "https://www.dolarsi.com/api/api.php?type=valoresprincipales"
  12.  
  13. r = requests.get(url)
  14.  
  15. # pprint(r.json())
  16.  
  17.  
  18. for item in r.json():
  19.     print(f"""
  20.     Activo: {item['casa']['nombre']}
  21.     Precio de venta: {item['casa']['venta']}
  22.     Precio de compra: {item['casa']['compra']}
  23.     """)
  24. '''
  25. lat = -38.416097
  26. lon = -63.616672
  27. API_key = "db7ba55a8af3d8d738d88349a7c9380d"
  28.  
  29.  
  30. url = f"https://api.openweathermap.org/data/2.5/forecast?lat={lat}&lon={lon}&units=metric&lang=es&appid={API_key}"
  31.  
  32. r = requests.get(url)
  33.  
  34. lista = r.json()["list"]
  35.  
  36. for item in lista:
  37.     print(f"""
  38.     Hora: {datetime.fromtimestamp(item['dt'])}
  39.     Descripción: {item['weather'][0]['description']}
  40.     Temperatura: {item['main']['temp']}ºC
  41.     Sensacion termica: {item['main']['feels_like']}ºC
  42.     Velocidad del viento: {item['wind']['speed']} km/h
  43.     Presion atm: {item['main']['pressure']} HPa
  44.     Humedad relativa ambiente: {item['main']['humidity']}%
  45.     """)
  46.  
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement