《纽约时报》竞选财务api的python客户端
nytcampfin的Python项目详细描述
《纽约时报》[campaign finance api](http://developer.nytimes.com/docs/campaign_finance_api)的一个非常基本的python客户端。您需要一个api密钥,该密钥应该设置为运行测试的环境变量。客户端只返回json,而不是完整的python对象,并尝试在times的api中实现每个响应。
安装
$ pip install nytcampfin
或下载并运行
$ python setup.py install
要求
NYT Campfin使用[Kenneth Reitz的请求库](https://github.com/kennethreitz/requests)检索API端点,使用[Roman Haritonov的请求缓存库](https://github.com/reclosedev/requests-cache)进行本地缓存。缓存已预配置为使用本地sqlite数据库,并设置为在5分钟后过期。
测试
要运行测试,请将api key设置为环境变量nyt_campfin_api_key:
$ export NYT_CAMPFIN_API_KEY=YOUR-API-KEY
然后运行测试:
$ python test.py
测试中禁用了缓存的使用。
用法
>>> from nytcampfin import NytCampfin >>> finance = NytCampfin(YOUR_NYT_CAMPAIGN_FINANCE_API_KEY)# retrieve today’s filings >>> today = finance.filings.today() >>> today[0][‘filing_id’] 793150
# retrieve a committee’s details >>> cmte = finance.committees.get(‘C00490219’,2012) >>> cmte[‘id’] u’C00490219’
# retrieve a candidate’s details >>> cand = finance.candidates.get(‘H4NY11138’) >>> cand[‘name’] u’CLARKE, YVETTE D’
请参阅测试以获取更多示例。
有关修补程序/拉取请求的说明
- Fork the project.
- Make your feature addition or bug fix.
- Add tests for it.
- Send a pull request. Bonus points for topic branches.
版权所有
版权所有(c)2012纽约时报公司。有关详细信息,请参见许可证。