用于与Sunlight Labs透明数据API交互的库
python-transparencydata的Python项目详细描述
用于与transparencydata.com api交互的python库。
transparencydata.com API提供了活动贡献和游说数据。
http://transparencydata.com/api/
python transparencydata是sunlight labs(c)2010的一个项目 作者jeremy carbaugh<;jcarbaugh@sunlightfoundation.com>;
所有代码都在bsd样式的许可证下,有关详细信息,请参见许可证。
来源:http://github.com/sunlightlabs/python-transparencydata/
要求
python=2.4
simplejson>;=1.8(python 2.6不需要,将使用内置的jsonmodule)
用法
要初始化api,只需要导入它并 要定义的API密钥。
(如果您没有api密钥,请访问http://services.sunlightlabs.com/api/ 注册一个。)
导入透明数据类并设置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
- 小于指定值。
- 介于
介于较小值和较大值之间。参数必须作为二值元组或列表传递。
>>> td.contributions(date__between=(start_date, end_date))
- 输入
- 匹配一系列值中的任意值。参数必须是元组或列表。
请参阅参数文档(http://transparencydata.com/api/)以了解哪些运算符对每个参数有效。
竞选捐款
查找2008年选举周期内加州对克里斯·范·霍伦的所有贡献:
>>> td.contributions(cycle=2008, contributor_state='CA', recipient_ft='van hollen')
可以通过编程方式访问有效贡献参数列表:
>>> print td.contributions.parameters
游说
寻找约翰·旺德里奇进行的所有游说活动:
>>> td.lobbying(lobbyist_ft='john wonderlich')
可以通过编程方式访问有效游说参数列表:
>>> print td.lobbying.parameters