Skip to content

unofficial python library for interacting with Sunlight Lab's Real Time Congress API

Notifications You must be signed in to change notification settings

ecocity/RTC-python-library

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

RTC Python Library

Requirements

python >= 2.6

Example Usage

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


sections = ('bill_id', 'sponsor', 'committees')
result = Bill.get_bill(bill_id='hr3-112', sections=sections)
print bill.sponsor_id, bill.vetoed, bill.last_action.text

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 Contributers

  • 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): #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 actions(cls, bill_id, sections=('actions',)): 
        """doc string goes here"""        
        #'sections' parameter above specifies what default sections to pull from a collection
        func = "bills"  #the collection were using (eg: bills.json)
        params = {'bill_id': bill_id}
        result = super(Bill, cls).get(func, params, sections)
        bill = result.bills[0]
        return [i for i in bill.actions]

When writing a classmethod you can skip creating the obj and just return a dictionary instead. Just specify 'make_obj=False' when declaring the classmethod parameters.


    ...
    @classmethod
    def titles(cls, bill_id, sections=('titles',), make_obj=False):
        ...
        response = super(Bill, cls).get(func, params, sections, make_obj) #remember to declare make_obj
        ...
    ...

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 a test function in RTCtest.py after writing a new classmethod

About

unofficial python library for interacting with Sunlight Lab's Real Time Congress API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published