-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp2.py
More file actions
36 lines (33 loc) · 1.08 KB
/
Copy pathp2.py
File metadata and controls
36 lines (33 loc) · 1.08 KB
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
import requests
apikey="893ee768cd339b85a0b48ed7617760c9"
city=input("Enter city name: ")
geo_url = f"http://api.openweathermap.org/geo/1.0/direct?q={city}&limit=1&appid={apikey}"
georesponse=requests.get(geo_url)
if georesponse.status_code==200 and georesponse.json():
geo_data=georesponse.json()[0]
lati=geo_data['lat']
long=geo_data['lon']
aqi_url = f"http://api.openweathermap.org/data/2.5/air_pollution?lat={lati}&lon={long}&appid={apikey}"
aqi_response = requests.get(aqi_url)
if aqi_response.status_code==200:
aqi_data=aqi_response.json()
aqi=aqi_data['list'][0]['main']['aqi']
if aqi==1:
c="Good Enough"
elif aqi ==2:
c="Fair"
elif aqi ==3:
c="Moderate"
elif aqi ==4:
c="poor"
elif aqi==5:
c="Hazardeous"
else:
c="unknown"
print("City :",city)
print("Air Quality Index :", aqi)
print("Condition of surrounding: ",c)
else:
print("ERROR:",aqi_response.status_code)
else:
print("City Not Found")