首页 空气质量指数 空气质量指数示例代码 空气质量指数查询[Python]

空气质量指数查询示例代码[Python]

作者:liuxiaojie 阅读数:2551 上传时间:2016-03-10

空气质量指数查询

#!/usr/bin/python
# encoding:utf-8

import urllib2, json, urllib



#  1、空气质量指数查询


data = {}
data["appkey"] = "your_appkey_here"
data["city"] = "杭州"

url_values = urllib.urlencode(data)
url = "https://api.jisuapi.com/aqi/query" + "?" + url_values
request = urllib2.Request(url)
result = urllib2.urlopen(request)
jsonarr = json.loads(result.read())

if jsonarr["status"] != u"0":
    print jsonarr["msg"]
    exit()
result = jsonarr["result"]

print result["cityid"],result["city"],result["so2"],result["so224"],result["no2"],result["no224"],result["co"],result["co24"],result["o3"],result["o38"],result["o324"],result["pm10"],result["pm1024"],result["pm2_5"],result["pm2_524"],result["iso2"],result["ino2"],result["ico"],result["io3"],result["io38"],result["ipm10"],result["ipm2_5"],result["aqi"],result["primarypollutant"],result["quality"],result["timepoint"]
print result["aqiinfo"]["level"],result["aqiinfo"]["color"],result["aqiinfo"]["affect"],result["aqiinfo"]["measure"]

for position in result["position"]:
    print position["positionname"],position["so2"],position["so224"],position["no2"],position["no224"],position["co"],position["co24"],position["o3"],position["o38"],position["o324"],position["pm10"],position["pm1024"],position["pm2_5"],position["pm2_524"],position["iso2"],position["ino2"],position["ico"],position["io3"],position["io38"],position["ipm10"],position["ipm2_5"],position["aqi"],position["primarypollutant"],position["quality"],position["timepoint"]