-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new file: dist/openair-0.1.0.tar.gz modified: example.py new file: openair.egg-info/PKG-INFO new file: openair.egg-info/SOURCES.txt new file: openair.egg-info/dependency_links.txt new file: openair.egg-info/top_level.txt new file: openair/__init__.py new file: openair/__init__.pyc new file: openair/air_class.py new file: openair/air_class.pyc new file: openair/data/__init__.py new file: openair/data/__init__.pyc new file: openair/data/station_data.py new file: openair/data/station_data.pyc new file: setup.py deleted: air_class.py deleted: function/__init__.py deleted: function/function.py deleted: function/station_data.py
- Loading branch information
1 parent
4cd5ea1
commit fa8c8a0
Showing
16 changed files
with
197 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Metadata-Version: 1.0 | ||
Name: openair | ||
Version: 0.1.0 | ||
Summary: This project is to fetch data from the official Silverlight application of Ministry of Environmental Protection of China (http://106.37.208.233:20035/), which publish realtime air quality. 本项目旨在方便地获取官方发布的全国空气质量数据。 | ||
Home-page: https://ovo.qaq.ac.cn | ||
Author: hebingchang | ||
Author-email: [email protected] | ||
License: MIT | ||
Description: UNKNOWN | ||
Keywords: aqi,air,china | ||
Platform: any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
setup.py | ||
openair/__init__.py | ||
openair/air_class.py | ||
openair.egg-info/PKG-INFO | ||
openair.egg-info/SOURCES.txt | ||
openair.egg-info/dependency_links.txt | ||
openair.egg-info/top_level.txt | ||
openair/data/__init__.py | ||
openair/data/station_data.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
openair |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#-*- encoding: utf-8 -*- | ||
import StringIO, requests, re, base64, zlib, xmltodict, json | ||
from io import BytesIO | ||
from wcf.records import * | ||
from wcf.xml2records import XMLParser | ||
import data.station_data | ||
|
||
# https://github.com/ernw/python-wcfbin | ||
|
||
class airChina(): | ||
def __init__(self): | ||
self.provinceList = json.loads(data.station_data.provinceList_json) | ||
|
||
def pListSearch(self, fromform, value): | ||
if fromform == 0: | ||
return {value: self.provinceList[str(value)]} | ||
else: | ||
for i in self.provinceList: | ||
if self.provinceList[i][fromform-1].lower() == value.lower(): | ||
return {i: self.provinceList[str(i)]} | ||
return None | ||
|
||
def getResponse(self, action, data): | ||
output = StringIO.StringIO() | ||
output.write('<'+action+' xmlns="http://tempuri.org/">'+data+'</'+action+'>') | ||
output.seek(0) | ||
|
||
r = XMLParser.parse(output) | ||
req = dump_records(r) | ||
|
||
r = requests.post(url='http://106.37.208.233:20035/ClientBin/Env-CnemcPublish-RiaServices-EnvCnemcPublishDomainService.svc/binary/'+action, | ||
data=req, | ||
headers={'Content-Type': 'application/msbin1'}) | ||
res = r.content | ||
|
||
buf = BytesIO(res) | ||
r = Record.parse(buf) | ||
|
||
print_records(r, fp=output) | ||
output.seek(0) | ||
|
||
pat = re.compile('<[^>]+>') | ||
enc = pat.sub('', output.readlines()[1][1:])[:-1] | ||
|
||
enc = base64.b64decode(enc) | ||
enc = zlib.decompress(enc) | ||
|
||
convertedDict = xmltodict.parse(enc) | ||
return json.dumps(convertedDict) | ||
|
||
#getInfo("GetProvincePublishLives", "<pid>9</pid>") | ||
#getInfo("GetAreaIaqiPublishLive", "<area>上海市</area>") | ||
#getInfo("GetCityDayAqiHistoryByCondition", "<cityCode>310000</cityCode>") | ||
def getAllStationsData(self): | ||
return json.loads(self.getResponse("GetAllAQIPublishLive", ""))["ArrayOfAQIDataPublishLive"]["AQIDataPublishLive"] | ||
|
||
def getProvinceStationsData(self, province, type=0): | ||
# 0: pid | ||
# 1: Chinese name | ||
# 2: Pinyin | ||
|
||
if type == 0: | ||
return json.loads(self.getResponse("GetProvincePublishLives", "<pid>"+str(province)+"</pid>"))["ArrayOfAQIDataPublishLive"]["AQIDataPublishLive"] | ||
else: | ||
pinfo = self.pListSearch(type, province) | ||
if pinfo != None: | ||
return json.loads(self.getResponse("GetProvincePublishLives", "<pid>"+str(pinfo.keys()[0])+"</pid>"))["ArrayOfAQIDataPublishLive"]["AQIDataPublishLive"] | ||
else: | ||
return None | ||
|
||
def getAllProvinceName(self): | ||
return json.loads(data.station_data.provinceList_json) | ||
|
||
def getProvinceAllCityName(self, pid): | ||
pjson = json.loads(data.station_data.stationList_json) | ||
ret = [] | ||
for c in pjson[str(pid)]: | ||
ret.append(c) | ||
|
||
return ret | ||
|
||
def getProvinceAllStationInfo(self, pid): | ||
pjson = json.loads(data.station_data.stationList_json) | ||
ret = [] | ||
for c in pjson[str(pid)]: | ||
for s in pjson[str(pid)][c]: | ||
ret.append(s) | ||
|
||
return ret | ||
|
||
def getCityAllStationInfo(self, pid, cityname): | ||
pjson = json.loads(data.station_data.stationList_json) | ||
try: | ||
return pjson[str(pid)][cityname] | ||
except: | ||
return None | ||
|
||
def searchCity(self, city): | ||
sjson = json.loads(data.station_data.cityList_json) | ||
city = str(city) | ||
if sjson.has_key(city): | ||
return {city: sjson[city]} | ||
else: | ||
for c in sjson: | ||
if sjson[c] == city: | ||
return {c: sjson[c]} | ||
|
||
return None | ||
|
||
def getCityHistory(self, city): | ||
return json.loads(self.getResponse("GetCityDayAqiHistoryByCondition", "<cityCode>"+self.searchCity(city).keys()[0]+"</cityCode>"))["ArrayOfCityDayAQIPublishHistory"]["CityDayAQIPublishHistory"] | ||
|
||
#def getAreaAQI(self): | ||
# return json.loads(self.getResponse("ArrayOfIAQIDataPublishLive", u"<area>上海市</area>")) | ||
|
Binary file not shown.
Empty file.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#-*- coding: utf-8 -*- | ||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name='openair', | ||
version='0.1.0', | ||
keywords = ('aqi', 'air', 'china'), | ||
description='This project is to fetch data from the official Silverlight application of Ministry of Environmental Protection of China (http://106.37.208.233:20035/), which publish realtime air quality. 本项目旨在方便地获取官方发布的全国空气质量数据。', | ||
license='MIT', | ||
author='hebingchang', | ||
author_email='[email protected]', | ||
url='https://ovo.qaq.ac.cn', | ||
platforms = 'any', | ||
packages = ['openair', 'openair.data'], | ||
install_require = ["wcf-binary-parser"] | ||
) |