Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- import requests
- from datetime import datetime
- r = requests.get('https://api.openweathermap.org/data/2.5/weather?q=Buenos%20Aires,AR&units=metric&lang=es&appid=6ce13bc6d5a965e991adaea8fce8676a')
- data = r.json()
- contador = 0
- # api_key = 6ce13bc6d5a965e991adaea8fce8676a
- print("Datos crudos:")
- print(data)
- print("\nDatos con formato:")
- print("--------------------")
- print("coordenadas:")
- # almacenamos la latitud y la longitud
- latitud = data['coord']['lat']
- longitud = data['coord']['lon']
- for clave, valor in list(data['coord'].items()):
- print("{:>12}: {}°".format(clave, valor))
- print("clima:")
- print("{:>12}: {}".format("Description", data['weather'][0]['description']))
- for clave, valor in list(data['main'].items()):
- if contador < 4:
- print("{:>12}: {}°C".format(clave, valor))
- if contador == 4:
- print("{:>12}: {} hPa".format(clave, valor))
- if contador == 5:
- print("{:>12}: {}%".format(clave, valor))
- contador += 1
- print("{:>12}: {} mts".format('visibility', data['visibility']))
- for clave, valor in list(data['wind'].items()):
- if clave == 'speed':
- print("{:>12}: {} km/h".format(clave, valor))
- r = requests.get('https://api.openweathermap.org/data/2.5/onecall?lat=-34.61&lon=-58.38&units=metric&lang=es&exclude={current,minutely,hourly}&appid=6ce13bc6d5a965e991adaea8fce8676a')
- data = r.json()
- print(data)
- print("\nPronostico:")
- for elemento in data['daily']:
- print()
- claves = list(elemento.keys())
- for clave,valor in elemento.items():
- if clave in ['dt','sunrise','sunset']:
- valor = int(valor)
- print(
- datetime.fromtimestamp(valor).strftime('%Y-%m-%d %H:%M:%S'))
- else:
- print(clave, valor)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement