Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. def aqi(keyword):
  2.     #first tries to search for overall city data matching the keyword
  3.     url = "https://api.waqi.info/feed/"
  4.     response = requests.request("GET", url + keyword + "/?token=" + token)
  5.     print(response.text)
  6.     aqiapi = json.loads(response.content.decode('UTF-8'))
  7.  
  8.     status = aqiapi['status']
  9.     if status != 'ok':
  10.         #if no result then make a search query
  11.         station = aqisearch(keyword)
  12.         try:
  13.             url = "https://api.waqi.info/feed/"
  14.             response2 = requests.request("GET", url + "@" + str(station) + "/?token=" + token)
  15.             #using the stationID to get detailed data - @ must come before stationID
  16.             print(response2.text)
  17.             aqiapi = json.loads(response2.content.decode('UTF-8'))
  18.             #load new data into aqiapi
  19.         except:
  20.                 print("Error1")
  21.  
  22.     else:
  23.         pass
  24.  
  25.     #Continue parsing data from city/station feed
  26.     try:
  27.         CurrentAQI = aqiapi['data']['aqi']
  28.         location = aqiapi['data']['city']['name']
  29.         readingtime = aqiapi['data']['time']['s']
  30.         mainpol = aqiapi['data']['dominentpol']
  31.         sendmsg("[" + location + "]  " + "AQI: " + str(CurrentAQI) + " | Air Quality Rating: " + airrating(CurrentAQI) + " | Main pollutant: " + polformat(mainpol) + " | Reading taken: " + readingtime + " (local time)")
  32.     except Exception as e:
  33.         pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement