跳转到主要内容

与Sunlight Labs Transparency Data API交互的库

项目描述

用于与TransparencyData.com API交互的Python库。

TransparencyData.com API提供竞选捐款和游说数据。

http://transparencydata.com/api/

python-transparencydata是Sunlight Labs的项目(c)2010 由Jeremy Carbaugh编写 <jcarbaugh@sunlightfoundation.com>

所有代码都在BSD风格的许可证下,有关详情请参阅LICENSE。

源码: http://github.com/sunlightlabs/python-transparencydata/

需求

python >= 2.4

simplejson >= 1.8 (Python 2.6及以上版本不需要,将使用内置json模块)

用法

要初始化API,只需导入它并定义一个API密钥即可。

(如果您没有API密钥,请访问http://services.sunlightlabs.com/api/进行注册。)

导入TransparencyData类并设置您的API密钥

>>> from transparencydata import TransparencyData
>>> td = TransparencyData('sunlight-api-key')

参数运算符

某些参数允许多个值或大于、小于或介于操作。我们允许添加运算符,类似于Django ORM中使用的方法。运算符附加到参数名称的末尾,使用双下划线。

>>> td.contributions(amount=100)                        # contributions equal to 100 dollars
>>> td.contributions(amount__lt=100)            # contributions less than 100 dollars
>>> td.contributions(cycle=1990)                        # contributions from the 1990 election cycle
>>> td.contributions(cycle__in=(1990,2008)) # contributions from the 1990 and 2008 election cycles
gt

大于指定值。

lt

小于指定值。

between

介于较小值和较大值之间。参数必须传递为两个值的元组或列表。

>>> td.contributions(date__between=(start_date, end_date))
in

与任何值匹配。参数必须是元组或列表。

请参阅参数文档(http://transparencydata.com/api/)以了解每个参数的有效操作符。

竞选捐款

查找2008年竞选周期中来自加州对Chris Van Hollen的所有捐款

>>> td.contributions(cycle=2008, contributor_state='CA', recipient_ft='van hollen')

可以通过程序访问有效的捐款参数列表

>>> print td.contributions.parameters

参数文档:http://transparencydata.com/api/#contributions

响应文档:http://transparencydata.com/docs/#contributions

游说

查找John Wonderlich进行的所有游说活动

>>> td.lobbying(lobbyist_ft='john wonderlich')

可以通过程序访问有效的游说参数列表

>>> print td.lobbying.parameters

参数文档:http://transparencydata.com/api/#lobbying

响应文档:http://transparencydata.com/docs/#lobbying

项目详情


下载文件

下载适用于您平台文件的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

python-transparencydata-0.1.tar.gz(6.7 KB 查看哈希值

上传时间 源代码

支持者