Skip to content

Commit 6129709

Browse files
committed
Filter out clips based on bill_id and bioguide_id
1 parent 549ae6f commit 6129709

File tree

2 files changed

+56
-14
lines changed

2 files changed

+56
-14
lines changed

RTC.py

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def get_todays(cls, make_obj=True, sections=''):
326326
result = super(FloorUpdates, cls)._apicall(endpoint, sections, make_obj, **params)
327327
return result['floor_updates']
328328

329-
class Videos(RTC_Client):
329+
class HouseVideos(RTC_Client):
330330
""" Currently only supports house type videos """
331331
__help__ = RTC_helpers.VIDEO_HELPER
332332

@@ -337,27 +337,29 @@ def __str__(self):
337337
def get_by_bill(cls, bill_id, make_obj=False, sections=('clip_urls', 'duration',
338338
'legislative_day', 'clip_id',
339339
'video_id', 'bills', 'clips')):
340-
"""
341-
342-
"""
343340
endpoint = "videos.json"
344341
params = {'clips.bills': bill_id}
345-
results = super(Videos, cls)._apicall(endpoint, sections, make_obj, **params)
342+
results = super(HouseVideos, cls)._apicall(endpoint, sections, make_obj, **params)
346343
### Only include clips from each video that contain bill_id ###
347344
videos = []
348345
for v in results['videos']:
349346
if v.has_key('bills') and bill_id in v['bills']:
350-
videos.append(v)
351-
#################################################
347+
clips = []
348+
for c in v['clips']:
349+
if c.has_key('bills') and bill_id in c['bills']:
350+
clips.append(c)
351+
if len(clips) > 0:
352+
v['clips'] = clips
353+
videos.append(v)
352354
return videos
353355

354356
@classmethod
355-
def get_legislator_name(cls, name, make_obj=False, sections=('clip_urls', 'duration',
357+
def get_by_legislator_name(cls, name, make_obj=False, sections=('clip_urls', 'duration',
356358
'legislative_day', 'clip_id',
357359
'video_id', 'bills', 'clips')):
358360
endpoint = "videos.json"
359361
params = {'clips.legislator_names': name}
360-
results = super(Videos, cls)._apicall(endpoint, sections, make_obj, **params)
362+
results = super(HouseVideos, cls)._apicall(endpoint, sections, make_obj, **params)
361363
### Only include clips from each video that contain a legistrators name
362364
# Make sure results set has the legislators name sin it
363365
videos = []
@@ -374,7 +376,32 @@ def get_legislator_name(cls, name, make_obj=False, sections=('clip_urls', 'durat
374376
v['clips'] = clips
375377
videos.append(v)
376378

377-
#################################################
379+
return videos
380+
381+
382+
@classmethod
383+
def get_by_bioguide_id(cls, bioguide_id, make_obj=False, sections=('clip_urls', 'duration',
384+
'legislative_day', 'clip_id',
385+
'video_id', 'bills', 'clips')):
386+
endpoint = "videos.json"
387+
params = {'clips.bioguide_ids': bioguide_id}
388+
results = super(HouseVideos, cls)._apicall(endpoint, sections, make_obj, **params)
389+
### Only include clips from each video that contain a legistrators name
390+
# Make sure results set has the legislators name sin it
391+
videos = []
392+
for v in results['videos']:
393+
# Json examples in the documentation say there will be a
394+
# legislator_names however in practice they are not there
395+
#if v.has_key('bioguide_id') and name in v['bioguide_id']:
396+
clips = []
397+
for c in v['clips']:
398+
if c.has_key('bioguide_ids') and bioguide_id in c['bioguide_ids']:
399+
clips.append(c)
400+
401+
if len(clips) > 0:
402+
v['clips'] = clips
403+
videos.append(v)
404+
378405
return videos
379406

380407
class Amendments(RTC_Client):

tests/test_videos.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,38 @@
22
bill_id = 'hr2-112'
33
RTC.apikey = 'c448541518f24d79b652ccc57b384815'
44
leg_name = 'Mr. Poe of TX'
5+
bioguide_id = 'P000592'
6+
7+
58
def test_by_bill():
6-
videos = RTC.Videos.get_by_bill(bill_id)
9+
videos = RTC.HouseVideos.get_by_bill(bill_id)
710
assert len(videos) != 0, 'We expect at least one video to be returned'
811
for v in videos:
912
assert bill_id in v['bills'], 'The bill id that is being searched ' +\
1013
'for should be in list of bills that are returned'
1114

12-
videos = RTC.Videos.get_by_bill('hrnotabill')
15+
videos = RTC.HouseVideos.get_by_bill('hrnotabill')
1316
assert len(videos) == 0, 'not bills should match this bill id'
1417

1518
def test_by_legislator_name():
16-
results = RTC.Videos.get_legislator_name(leg_name)
19+
results = RTC.HouseVideos.get_by_legislator_name(leg_name)
1720
assert len(results) != 0, 'We expect at least one video to be returned'
1821
for r in results:
1922
for c in r['clips']:
2023
assert leg_name in c['legislator_names'], 'Expecited name to ' +\
2124
'be in legislator_names %s' % leg_name
2225

23-
results = RTC.Videos.get_legislator_name('not a legislator name')
26+
results = RTC.HouseVideos.get_by_legislator_name('not a legislator name')
2427
assert len(results) == 0, 'there should be no legislators with this name'
28+
29+
def test_by_bioguide_id():
30+
results = RTC.HouseVideos.get_by_bioguide_id(bioguide_id)
31+
assert len(results) != 0, 'We expect at least one video to be returned'
32+
for r in results:
33+
for c in r['clips']:
34+
assert bioguide_id in c['bioguide_ids'], 'Expecited bioguide_id to ' +\
35+
'be in bioguide_ids %s' % bioguide_id
36+
37+
results = RTC.HouseVideos.get_by_bioguide_id('nobioguididhere')
38+
assert len(results) == 0, 'there should be no legislators with this bioguide_id'
39+

0 commit comments

Comments
 (0)