fetch weather data with api python

Solutions on MaxInterview for fetch weather data with api python by the best coders in the world

showing results for - "fetch weather data with api python"
Nael
06 Apr 2020
1Weather information of any place using Python
2import requests
3import os
4from datetime import datetime
5
6user_api = os.environ['current_weather_data']
7location = input("Enter the city name: ")
8
9complete_api_link = "https://api.openweathermap.org/data/2.5/weather?q="+location+"&appid="+user_api
10api_link = requests.get(complete_api_link)
11api_data = api_link.json()
12
13#create variables to store and display data
14temp_city = ((api_data['main']['temp']) - 273.15)
15weather_desc = api_data['weather'][0]['description']
16hmdt = api_data['main']['humidity']
17wind_spd = api_data['wind']['speed']
18date_time = datetime.now().strftime("%d %b %Y | %I:%M:%S %p")
19
20print ("-------------------------------------------------------------")
21print ("Weather Stats for - {}  || {}".format(location.upper(), date_time))
22print ("-------------------------------------------------------------")
23
24print ("Current temperature is: {:.2f} deg C".format(temp_city))
25print ("Current weather desc  :",weather_desc)
26print ("Current Humidity      :",hmdt, '%')
27print ("Current wind speed    :",wind_spd ,'kmph')
28