Skip to content

Commit c7bf15f

Browse files
committed
added a method to look up Documents by a specified date
wrote unit tests for it
1 parent a238242 commit c7bf15f

File tree

2 files changed

+50
-22
lines changed

2 files changed

+50
-22
lines changed

RTC.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,21 @@ def __init__(self):
7474
pass
7575

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

8181

8282
kwargs['apikey'] = apikey
8383
if not(sections == ''):
8484
kwargs['sections'] = ','.join([arg for arg in sections])
85-
86-
url = "{0}?{1}".format(urljoin(self.base_url, endpoint),
87-
urlencode(kwargs, doseq=True))
85+
if args:
86+
extra_arguments = "&{0}".format('&'.join(args))
87+
else:
88+
extra_arguments = ''
89+
url = "{0}?{1}{2}".format(urljoin(self.base_url, endpoint),
90+
urlencode(kwargs, doseq=True),
91+
extra_arguments)
8892
print url
8993
try:
9094
response = urlopen(url).read().decode('utf-8')
@@ -280,6 +284,21 @@ def cosponsors(cls, bill_id, make_obj=False, sections=('cosponsors',)):
280284
bill = result['bills'][0]
281285
return [i for i in bill['cosponsors']]
282286

287+
class Documents(RTC_Client):
288+
289+
# currently, the posted_at is the only guarenteed field
290+
# it used a timestamp format, which requires the url
291+
# to display it twice to do a '__gte' and '__lte'
292+
293+
@classmethod
294+
def get_by_date(cls, date, make_obj=False, sections=''):
295+
endpoint = "documents.json"
296+
begin_time = '%sT00:00:00' % date
297+
end_time = '%sT23:59:59' % date
298+
params = {'posted_at__gte':begin_time, 'posted_at__lte':end_time}
299+
result = super(Documents, cls)._apicall(endpoint, sections,
300+
make_obj, **params)
301+
return result['documents']
283302

284303
class Votes(RTC_Client):
285304
@classmethod

tests/RTCtest.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/python
21
"""
32
Simple test file to make sure each function is working.
43
Must be edited manually.
@@ -113,20 +112,30 @@ def video_test():
113112
print "* offset: %s | duration: %s | summary: %s " %\
114113
(clip['offset'], clip['duration'], clip['events'][0])
115114

116-
117-
bill()
118-
mult_bills()
119-
bill_actions()
120-
bill_passage_votes()
121-
bill_committees()
122-
bill_titles()
123-
bill_amendments()
124-
bill_related_bills()
125-
bill_cosponsors()
126-
127-
votes()
128-
floor_updates()
129-
floor_updates_search()
130-
get_mult_floor_updates()
131-
todays_floor_updates()
132-
video_test()
115+
# documents tests
116+
def document_test():
117+
document_list = RTC.Documents.get_by_date('2011-03-14')
118+
print pprint(document_list)
119+
120+
#bill()
121+
#mult_bills()
122+
#bill_actions()
123+
#bill_passage_votes()
124+
#bill_committees()
125+
#bill_titles(
126+
#bill_amendments()
127+
#bill_related_bills()
128+
#bill_cosponsors()
129+
130+
#votes()
131+
#floor_updates()
132+
#floor_updates_search()
133+
#get_mult_floor_updates()
134+
#todays_floor_updates()
135+
#video_test()
136+
document_test()
137+
138+
139+
140+
if __name__ == '__main__':
141+
pass

0 commit comments

Comments
 (0)