-
Notifications
You must be signed in to change notification settings - Fork 0
/
weatherapi.py
32 lines (26 loc) · 1.27 KB
/
weatherapi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import requests
import os
from datetime import datetime
user_api = os.environ['current_weather data']
location = input("Enter the city name: ")
complete_api_link="https://api.openweathermap.org/data/2.5/weather?q="+location+"&appid="+user_api
api_link = requests.get(complete_api_link)
api_data = api_link.json()
if api_data['cod']=="404":
print ("Invalid City: (). Please check you City name".format(location))
else:
#create variables to store and display data
temp_city = ((api_data['main']['temp'])-273.15)
weather_desc = api_data ['weather'][0]['description']
hmdt = api_data['main']['humidity']
wind_spd = api_data['wind']['speed']
country_name = api_data ['sys']['country']
date_time = datetime.now().strftime("%d %b %Y | %I:%M:%S %p")
print ("-----------------------------------------------------------------")
print ("Weather Stats for - {} || {}".format(location.upper(), date_time))
print ("-----------------------------------------------------------------")
print ("Country :",country_name)
print ("Current temperature is: {:.2f} deg C".format(temp_city))
print ("Current weather desc :",weather_desc)
print ("Current Humidity :",hmdt, '%')
print ("Current wind speed :",wind_spd,'kaph')