Created
September 15, 2021 18:40
-
-
Save seyhunak/d69590f96de7828a2632a17c1b9e2c46 to your computer and use it in GitHub Desktop.
Write a Python program to get current weather in Azerbaijan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
def get_current_weather(city): | |
url = 'http://api.openweathermap.org/data/2.5/weather' | |
params = { | |
'q': city, | |
'appid': '11c0d3dc6093f7442898ee49d2430d20', | |
'units': 'metric' | |
} | |
res = requests.get(url, params=params) | |
data = res.json() | |
print(f"Current weather in {city}:") | |
print(f"Temperature: {data['main']['temp']} C") | |
print(f"Humidity: {data['main']['humidity']}%") | |
print(f"Pressure: {data['main']['pressure']} hPa") | |
print(f"Wind speed: {data['wind']['speed']} m/s") | |
if __name__ == "__main__": | |
get_current_weather('Baku') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment