Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def aqi(keyword):
- #first tries to search for overall city data matching the keyword
- url = "https://api.waqi.info/feed/"
- response = requests.request("GET", url + keyword + "/?token=" + token)
- print(response.text)
- aqiapi = json.loads(response.content.decode('UTF-8'))
- status = aqiapi['status']
- if status != 'ok':
- #if no result then make a search query
- station = aqisearch(keyword)
- try:
- url = "https://api.waqi.info/feed/"
- response2 = requests.request("GET", url + "@" + str(station) + "/?token=" + token)
- #using the stationID to get detailed data - @ must come before stationID
- print(response2.text)
- aqiapi = json.loads(response2.content.decode('UTF-8'))
- #load new data into aqiapi
- except:
- print("Error1")
- else:
- pass
- #Continue parsing data from city/station feed
- try:
- CurrentAQI = aqiapi['data']['aqi']
- location = aqiapi['data']['city']['name']
- readingtime = aqiapi['data']['time']['s']
- mainpol = aqiapi['data']['dominentpol']
- sendmsg("[" + location + "] " + "AQI: " + str(CurrentAQI) + " | Air Quality Rating: " + airrating(CurrentAQI) + " | Main pollutant: " + polformat(mainpol) + " | Reading taken: " + readingtime + " (local time)")
- except Exception as e:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement