-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10b.py
43 lines (29 loc) · 1.04 KB
/
10b.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
33
34
35
36
37
38
39
40
41
42
43
'''
10.b
Write a python program to fetch current weather data from the JSON file
'''
import requests, json
api_key = "360396a690bbdadea6dafcdfecd8df66"
base_url = "http://api.openweathermap.org/data/2.5/weather?"
#https://api.openweathermap.org/data/2.5/weather?q=London&appid=360396a690bbdadea6dafcdfecd8df66
entered_city = input("Enter city name : ")
complete_url = base_url + "q=" + entered_city +"&appid=" + api_key
response = requests.get(complete_url)
x = response.json()
#print(x)
if x["cod"] != "404":
temperature = x["main"]["temp"]
pressure = x["main"]["pressure"]
humidity = x["main"]["humidity"]
weather = x["weather"]
weather_description = weather[0]["description"]
print('\033[1m' + "Weather description is: "+str(weather_description) + '\033[0m')
print("Additional Weather description is follows:\n")
print("\n\n Temparature is = " +
str(temperature) +
"\n Atmospheric pressure = " +
str(pressure) +
"\n Humidity = " +
str(humidity))
else:
print(" Please enter valid city name ")