Skip to content

Instantly share code, notes, and snippets.

@seyhunak
Created September 15, 2021 18:40
Show Gist options
  • Save seyhunak/d69590f96de7828a2632a17c1b9e2c46 to your computer and use it in GitHub Desktop.
Save seyhunak/d69590f96de7828a2632a17c1b9e2c46 to your computer and use it in GitHub Desktop.
Write a Python program to get current weather in Azerbaijan
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