-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_api.py
37 lines (34 loc) · 1.19 KB
/
main_api.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
import urllib.parse
import requests
main_api = 'http://api.openaq.org/v1/latest?'
# Main Logic
while True:
city = input("Location :")
url = main_api + urllib.parse.urlencode({'city': city})
json_data = requests.get(url).json()
status = json_data['meta']['found']
if status == 0:
print("There is No data Avalible")
else:
formatted_location = json_data['results'][0]['location']
print(formatted_location)
for each in json_data['results'][0]['measurements']:
# print(each['parameter'], each['value'])
if each['parameter'] == 'co':
co = each['value']
elif each['parameter'] == 'so2':
so2 = each['value']
elif each['parameter'] == 'pm10':
pm10 = each['value']
elif each['parameter'] == 'pm25':
pm25 = each['value']
elif each['parameter'] == 'o3':
o3 = each['value']
elif each['parameter'] == 'no2':
no2 = each['value']
print("CO :", co)
print("NO2 :", no2)
print("O3 :", o3)
print("PM10 :", pm10)
print("SO2 :", so2)
print("PM2.5 :", pm25)