Skip to content

Commit

Permalink
added a method to look up Documents by a specified date
Browse files Browse the repository at this point in the history
wrote unit tests for it
  • Loading branch information
mhjohnson committed Sep 23, 2011
1 parent a238242 commit c7bf15f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 22 deletions.
27 changes: 23 additions & 4 deletions RTC.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,21 @@ def __init__(self):
pass

@classmethod
def _apicall(self, endpoint, sections='', make_obj=False, **kwargs):
def _apicall(self, endpoint, sections='', make_obj=False, *args, **kwargs):
if not apikey:
raise Exception('API key must be set')


kwargs['apikey'] = apikey
if not(sections == ''):
kwargs['sections'] = ','.join([arg for arg in sections])

url = "{0}?{1}".format(urljoin(self.base_url, endpoint),
urlencode(kwargs, doseq=True))
if args:
extra_arguments = "&{0}".format('&'.join(args))
else:
extra_arguments = ''
url = "{0}?{1}{2}".format(urljoin(self.base_url, endpoint),
urlencode(kwargs, doseq=True),
extra_arguments)
print url
try:
response = urlopen(url).read().decode('utf-8')
Expand Down Expand Up @@ -280,6 +284,21 @@ def cosponsors(cls, bill_id, make_obj=False, sections=('cosponsors',)):
bill = result['bills'][0]
return [i for i in bill['cosponsors']]

class Documents(RTC_Client):

# currently, the posted_at is the only guarenteed field
# it used a timestamp format, which requires the url
# to display it twice to do a '__gte' and '__lte'

@classmethod
def get_by_date(cls, date, make_obj=False, sections=''):
endpoint = "documents.json"
begin_time = '%sT00:00:00' % date
end_time = '%sT23:59:59' % date
params = {'posted_at__gte':begin_time, 'posted_at__lte':end_time}
result = super(Documents, cls)._apicall(endpoint, sections,
make_obj, **params)
return result['documents']

class Votes(RTC_Client):
@classmethod
Expand Down
45 changes: 27 additions & 18 deletions tests/RTCtest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/python
"""
Simple test file to make sure each function is working.
Must be edited manually.
Expand Down Expand Up @@ -113,20 +112,30 @@ def video_test():
print "* offset: %s | duration: %s | summary: %s " %\
(clip['offset'], clip['duration'], clip['events'][0])


bill()
mult_bills()
bill_actions()
bill_passage_votes()
bill_committees()
bill_titles()
bill_amendments()
bill_related_bills()
bill_cosponsors()

votes()
floor_updates()
floor_updates_search()
get_mult_floor_updates()
todays_floor_updates()
video_test()
# documents tests
def document_test():
document_list = RTC.Documents.get_by_date('2011-03-14')
print pprint(document_list)

#bill()
#mult_bills()
#bill_actions()
#bill_passage_votes()
#bill_committees()
#bill_titles(
#bill_amendments()
#bill_related_bills()
#bill_cosponsors()

#votes()
#floor_updates()
#floor_updates_search()
#get_mult_floor_updates()
#todays_floor_updates()
#video_test()
document_test()



if __name__ == '__main__':
pass

0 comments on commit c7bf15f

Please sign in to comment.