Pythonic API到WMO OSCAR Web Services
项目描述
pyoscar
Pythonic API到WMO OSCAR
概述
pyoscar提供了基于WMO OSCAR HTTP API的Pythonic API。
对于R爱好者
对于有兴趣使用R的用户,oscarr项目为R社区提供了一个pyoscar Python模块的R包装器。
安装
要求
- Python 3
- virtualenv或Conda
依赖关系
依赖关系列在requirements.txt中。依赖关系将在安装pyoscar时自动安装。
安装pyoscar
对于用户
安装最新稳定版本
pip3 install pyoscar
保持与稳定更新的同步
pip3 install pyoscar -U
对于开发者
# setup virtualenv
python3 -m venv pyoscar
cd pyoscar
source bin/activate
# clone codebase and install
git clone https://github.com/wmo-cop/pyoscar.git
cd pyoscar
python3 setup.py build
python3 setup.py install
通过命令行运行pyoscar
# help
pyoscar --help
# get version
pyoscar --version
# all subcommands support the following options:
# --env (depl or prod, default depl)
# --verbosity (ERROR, WARNING, INFO, DEBUG, default NONE)
# get all station identifiers
pyoscar stations
# get all station identifiers by country
pyoscar stations --country=CAN
# get all station identifiers by program affiliation
pyoscar stations --program=GAW
# get a single station by WIGOS identifier
pyoscar station 0-20000-0-71151
# get a single station by WIGOS identifier in summary mode
pyoscar station 0-20000-0-71151 --summary
# get a single station by WIGOS identifier in WIGOS XML format
pyoscar station 0-20000-0-71151 --format=XML
# get a single station by WIGOS identifier in WIGOS XML format in summary mode
pyoscar station 0-20000-0-71151 --format=XML --summary
# add verbose mode (ERROR, WARNING, INFO, DEBUG)
pyoscar station 0-20000-0-71151 --verbosity=DEBUG
# get contact by country
pyoscar contact -c Canada
# get contact by surname
pyoscar contact -s Karn
# get contact by organization
pyoscar contact -o "Environment Canada"
# upload WMDR XML (to production environment)
pyoscar upload -x /path/to/wmdr.xml -at API_TOKEN -e prod
# upload WMDR XML (to production environment) and save results to file
pyoscar upload -x /path/to/wmdr.xml -at API_TOKEN -e prod -l results.log
# use only GML ids is TRUE by default; use --no-gml-ids to set to FALSE
pyoscar upload -x /path/to/wmdr.xml -at API_TOKEN -e prod -l results.log --no-gml-ids
# harvest all records
pyoscar harvest --env=prod --directory=/path/to/dir
使用pyoscar API
from pyoscar import OSCARClient
client = OSCARClient()
# get all Canadian stations
stations = client.get_stations(country='CAN')
# get all Canadian stations
stations = client.get_stations(program='GAW')
# get invididual station report
stn_leo = client.get_station_report('0-20000-0-71758')
# get invididual station report in summary mode
stn_leo = client.get_station_report('0-20000-0-71758', summary=True)
# upload WMDR XML
## instantiate client to OSCAR DEPL (default)
client = OSCARClient(api_token='foo')
## ...or to OSCAR production
client = OSCARClient(api_token='foo', env='prod')
with open('some-wmdr-file.xml') as fh:
data = fh.read()
response = client.upload(data)
开发
运行测试
# install dev requirements
pip3 install -r requirements-dev.txt
# run tests like this:
cd tests
python3 run_tests.py
# or like this:
python3 setup.py test
# measure code coverage
coverage run --source pyoscar setup.py test
coverage report -m
发布
create release (x.y.z is the release version)
vi pyoscar/__init__.py # update __version__
git commit -am 'update release version x.y.z'
git push origin master
git tag -a x.y.z -m 'tagging release version x.y.z'
git push --tags
# upload to PyPI
rm -fr build dist *.egg-info
python3 setup.py sdist bdist_wheel --universal
twine upload dist/*
# publish release on GitHub (https://github.com/wmo-cop/pyoscar/releases/new)
# bump version back to dev
vi pyoscar/__init__.py # update __version__
git commit -am 'back to dev'
git push origin master
代码约定
错误和问题
所有错误、增强和问题都由GitHub管理。
联系方式
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪一个,请了解有关安装包的更多信息。
源代码分发
pyoscar-0.8.0.tar.gz (11.9 kB 查看散列值)
构建分发
pyoscar-0.8.0-py2.py3-none-any.whl (11.1 kB 查看散列值)