Skip to content

pythonclt/RTC-Python-Wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RTC Python Wrapper Library

WARNING: This may create a more transparent government. If you don't want change then stop reading here.

Update 09-20-2011

  • Started cleaning up and improving the README file.

UPDATE 06-18-2011

Added a classmethod to query multiple bills in one request. This is very efficient for cases that require iterations through a list of bill_ids. Usage:


bill_list = ['hr1-112', 'hr2-112']
\#note: setting sections='', will request all sections for each bill
bills = RTC.get_mult_bills(bill_list, sections='')

See RTCtest.py for a full example.

Requirements

  • python >= 2.6
  • unittest2

Use the following command to clone the repository locally to work on it:


git clone [email protected]:pythonclt/RTC-Python-Wrapper.git

List of Files

  • README.markdown - you're reading it
  • requirements.txt - list of required Python packages
  • RTC_helpers.py - Simple file to hold help and doc string text related to the RTC python library.
  • RTC.py - Python library for interacting with the Sunlight Labs Real Time Congress API.
  • RTCtest.py - Simple test file to make sure each function is working.

Example Usage

You can specify the sections you want to pull from the RESTful API.


sections = ('bill_id', 'sponsor', 'committees')
bill = Bill.get_bill(bill_id='hr3-112', sections=sections)
print bill['sponsor_id']

Otherwise, it uses the default that's specified in the library.


bill = RTC.Bill.get_bill(bill_id)
print bill['sponsor_id'], bill['vetoed'], bill['last_action']['text']

See RTCtest.py for more examples usage.

Development Notes for Contributors

  • dict2obj is a function that coverts the json converted dictionary into a usable object. Since much of the RTC API's fields are not guaranteed, this may help avoid the extra coding for keyErrors. Additionally, it is convenient to use dot notation instead of dictionaries.

###How to create class methods for collections This is the basic structure:


class Bill(RTC_Client): #name of collection (eg: bills, videos, floor, updates)
    """  __doc_\_ string goes here """
    __help_\_ = RTC_helpers.BILL_HELPER #string created and imported from RTC_helpers.py
    ...
    @classmethod
    def get_bill(cls, bill_id, make_obj=False, sections=RTC_helpers.BILL_DEFAULT_SECTIONS):
        endpoint = "bills.json"
        params = {'bill_id': bill_id}
        result = super(Bill, cls)._apicall(endpoint, sections, make_obj, **params)
        bill = result['bills'][0]
        return bill

Running tests

Set your PYTHONPATH to the top-level directory--the one containing the RTC.py file. In *nix-land, do this: $ export PYTHONPATH=/path/to/top/level/directory In Windows-land, do something like this: PYTHONPATH=%path%;\path\to\top\level\directory

You can run individual tests like this: $ python tests/TestRTC.py

Also, you can run all tests like this: $ python tests

Other comments

  • It'd be helpful to enter helper text into the RTC_helpers.py after writing a new classmethod
  • It'd be helpful to write some tests after writing a new classmethod. See "tests/dummy.py" to get started.

About

Python wrapper for the Sunlight Lab's Real Time Congress API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 7