跳转到主要内容

用于与Sunlight Labs API交互的库

项目描述

用于与Sunlight Labs API交互的Python库。

Sunlight Labs API提供立法者信息和地区搜索。

(http://services.sunlightlabs.com/api/)

python-sunlightapi 是Sunlight Labs的项目 (c) 2010。由James Turk编写 <jturk@sunlightfoundation.com>。

所有代码均采用BSD样式许可,有关详情请参阅LICENSE。

主页: http://pypi.python.org/pypi/python-sunlightapi/

源代码: http://github.com/sunlightlabs/python-sunlightapi/

该包可以通过pip、easy_install安装,或下载源代码并运行 python setup.py install

要求

python >= 2.4

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

用法

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

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

sunlightapi 导入 sunlight

>>> from sunlightapi import sunlight, SunlightApiError

并设置您的API密钥

>>> sunlight.apikey = 'your-key-here'

立法者方法

立法者命名空间包含多个功能
  • legislators.get - 获取单个立法者

  • legislators.getList - 获取零个或多个立法者

  • legislators.search - 根据姓名进行模糊搜索立法者

  • legislators.allForZip - 获取代表特定邮政编码的所有立法者

  • legislators.allForLatLong - 获取代表特定点的所有立法者

get 和 getList

legislators.get 和 legislators.getList 都可以接受任意数量的参数,并返回符合提供标准的所有立法者。这些参数也是每个立法者对象返回的参数。

可用的参数包括
  • title

  • firstname

  • middlename

  • lastname

  • name_suffix

  • nickname

  • party

  • state

  • district

  • in_office

  • gender

  • birthdate

  • phone

  • fax

  • website

  • webform

  • email

  • congress_office

  • bioguide_id

  • votesmart_id

  • fec_id

  • govtrack_id

  • crp_id

  • eventful_id

  • congresspedia_url

  • twitter_id

  • official_rss

  • youtube_url

  • senate_class

  • birthdate

要获取代表 NC-4 的代表

>>> print(sunlight.legislators.get(state='NC', district='4'))
Rep. David Price (D-NC)

legislators.getList 与此类似,但返回一个列表。可以进行更复杂的查询,例如“所有来自纽约的共和党立法者”

>>> for leg in sunlight.legislators.getList(state='NY', party='R'):
...     print(leg)
Rep. Pete King (R-NY)
Rep. Christopher Lee (R-NY)

建议不要在没有参数的情况下调用 getList,因为这将会检索所有立法者,如果您需要这样做,请自由地获取 http://services.sunlightlabs.com/api/ 上提供的 API 数据存档。

allForZip

legislators.allForZip 检索代表特定邮政编码的所有立法者。

这通常意味着两位参议员和一位(或多位)代表。

要获取代表邮政编码 27511 的所有立法者

>>> for legislator in sunlight.legislators.allForZip(27511):
...     print(legislator)
Rep. David Price (D-NC)
Sen. Kay Hagan (D-NC)
Sen. Richard Burr (R-NC)
Rep. Brad Miller (D-NC)

allForLatLong

legislators.allForLatLong 检索代表特定点的所有立法者。

这是调用 districts.getDistrictFromLatLong 并然后查找该地区的代表和州参议员的快捷方式。

要获取代表宾夕法尼亚州西部 41.92, -80.14 的地点的所有立法者

>>> for legislator in sunlight.legislators.allForLatLong(41.92, -80.14):
...     print(legislator)
Sen. Bob Casey (D-PA)
Sen. Arlen Specter (D-PA)
Rep. Kathy Dahlkemper (D-PA)

districts 方法

districts 命名空间包含两个功能
  • districts.getDistrictsFromZip

  • districts.getDistrictFromLatLong

getDistrictsFromZip

districts.getDistrictsFromZip 获取与给定邮政编码重叠的所有地区。

要获取与 14623 重叠的所有地区
>>> for district in sunlight.districts.getDistrictsFromZip(14623):
...     print(district)
NY-29
NY-28

getDistrictFromLatLong

districts.getDistrictFromLatLong 查找给定经纬度坐标对所在的地区。

要找出 61.13 N, 149.54 W 所在的地区
>>> print(sunlight.districts.getDistrictFromLatLong(61.13, 149.54))
AK-0

这个点实际上在阿拉斯加安克雷奇,所以这是正确的。

委员会方法

委员会命名空间包含
  • committee.getList

  • committee.get

  • committee.allForMember

getList

committee.getList 获取给定议院(众议院、参议院或联合议院)的所有委员会。

要查看当前议会的所有联合委员会
>>> for c in sunlight.committees.getList('Joint'):
...     print(c)
Joint Economic Committee
Joint Committee on Printing
Joint Committee on Taxation
Joint Committee on the Library

get

committee.get 获取给定委员会的完整详细信息,包括成员和子委员会。

获取委员会详细信息的示例

>>> com = sunlight.committees.get('HSAG')
>>> print(com.name)
House Committee on Agriculture
>>> for sc in com.subcommittees:
...     print(sc)
Subcommittee on  Conservation, Credit, Energy, and Research
Subcommittee on Department Operations, Oversight, Nutrition and Forestry
Subcommittee on General Farm Commodities and Risk Management
Subcommittee on Horticulture and Organic Agriculture
Subcommittee on Livestock, Dairy, and Poultry
Subcommittee on Rural Development, Biotechnology, Specialty Crops, and Foreign Agriculture
>>> for m in com.members:
...     print(m)
Rep. Joe Baca (D-CA)
Rep. John Boccieri (D-OH)
Rep. Leonard Boswell (D-IA)
Rep. Bobby Bright (D-AL)
Rep. Dennis Cardoza (D-CA)
Rep. Bill Cassidy (R-LA)
Rep. Travis Childers (D-MS)
Rep. Mike Conaway (R-TX)
Rep. Jim Costa (D-CA)
Rep. Henry Cuellar (D-TX)
Rep. Kathy Dahlkemper (D-PA)
Rep. Brad Ellsworth (D-IN)
Rep. Jeff Fortenberry (R-NE)
Rep. Bob Goodlatte (R-VA)
Rep. Sam Graves (R-MO)
Rep. Debbie Halvorson (D-IL)
Rep. Stephanie Herseth Sandlin (D-SD)
Rep. Tim Holden (D-PA)
Rep. Tim Johnson (R-IL)
Rep. Steven Kagen (D-WI)
Rep. Steve King (R-IA)
Rep. Larry Kissell (D-NC)
Rep. Frank Kratovil (D-MD)
Rep. Bob Latta (R-OH)
Rep. Frank Lucas (R-OK)
Rep. Blaine Luetkemeyer (R-MO)
Rep. Cynthia Lummis (R-WY)
Rep. Betsy Markey (D-CO)
Rep. Jim Marshall (D-GA)
Rep. Eric Massa (D-NY)
Rep. Mike McIntyre (D-NC)
Rep. Walt Minnick (D-ID)
Rep. Jerry Moran (R-KS)
Rep. Randy Neugebauer (R-TX)
Rep. Collin Peterson (D-MN)
Rep. Earl Pomeroy (D-ND)
Rep. Phil Roe (R-TN)
Rep. Mike Rogers (R-AL)
Rep. Mark Schauer (D-MI)
Rep. Jean Schmidt (R-OH)
Rep. Kurt Schrader (D-OR)
Rep. David Scott (D-GA)
Rep. Adrian Smith (R-NE)
Rep. G.T. Thompson (R-PA)
Rep. Tim Walz (D-MN)

allForLegislator

所有立法者显示了立法者的所有委员会和子委员会成员资格。

请注意,所包含的子委员会仅为成员所在的子委员会

显示立法者的所有委员会和子委员会
>>> for com in sunlight.committees.allForLegislator('S000148'):
...    print(com)
...    for sc in com.subcommittees:
...        print('   '+str(sc))
Senate Committee on Rules and Administration
Senate Committee on Finance
   Subcommittee on International Trade and Global Competitiveness
   Subcommittee on Social Security, Pensions and Family Policy
   Subcommittee on Taxation, IRS Oversight, and Long-term Growth
Joint Committee on the Library
Joint Economic Committee
Senate Commmittee on the Judiciary
   Subcommittee on Administrative Oversight and the Courts
   Subcommittee on Antitrust, Competition Policy and Consumer Rights
   Subcommittee on Crime and Drugs
   Subcommittee on Immigration, Refugees and Border Security
   Subcommittee on Terrorism and Homeland Security
Joint Committee on Printing
Senate Committee on Banking, Housing, and Urban Affairs
   Subcommittee on Securities, Insurance, and Investment
   Subcommittee on Financial Institutions
   Subcommittee on Housing, Transportation, and Community Development

项目详情


下载文件

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

源代码分发

python-sunlightapi-1.1.1.tar.gz (7.7 kB 查看哈希)

上传时间 源代码

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面