Skip to content

Commit

Permalink
new file: air_class.pyc
Browse files Browse the repository at this point in the history
	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
hebingchang committed Feb 15, 2017
1 parent 4cd5ea1 commit fa8c8a0
Show file tree
Hide file tree
Showing 16 changed files with 197 additions and 2 deletions.
Binary file added air_class.pyc
Binary file not shown.
Binary file added dist/openair-0.1.0.tar.gz
Binary file not shown.
9 changes: 7 additions & 2 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#-*- encoding: utf-8 -*-
import air_class, json
import json
from openair import air_class

air = air_class.airChina()
'''
# Get data of all air matters from each station in China
Expand Down Expand Up @@ -35,4 +37,7 @@
# param: city name or city code
cityHistory = air.getCityHistory(u"上海市")
print cityHistory
'''
'''

cityHistory = air.getCityHistory(u"上海市")
print cityHistory
11 changes: 11 additions & 0 deletions openair.egg-info/PKG-INFO
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
9 changes: 9 additions & 0 deletions openair.egg-info/SOURCES.txt
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
1 change: 1 addition & 0 deletions openair.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions openair.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
openair
1 change: 1 addition & 0 deletions openair/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file added openair/__init__.pyc
Binary file not shown.
115 changes: 115 additions & 0 deletions openair/air_class.py
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 added openair/air_class.pyc
Binary file not shown.
Empty file added openair/data/__init__.py
Empty file.
Binary file added openair/data/__init__.pyc
Binary file not shown.
36 changes: 36 additions & 0 deletions openair/data/station_data.py

Large diffs are not rendered by default.

Binary file added openair/data/station_data.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions setup.py
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"]
)

0 comments on commit fa8c8a0

Please sign in to comment.