Skip to content

Commit 5f9a296

Browse files
authored
Merge pull request #103 from z3c0/test
v1.0.3
2 parents abbdcd3 + 8fa36ae commit 5f9a296

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ Output:
335335

336336
The `load` method manually loads the dataset specified when instantiating `CongressBills`
337337

338+
[Return to top](#table-of-contents)
338339

339340
***
340341

vistos/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0
1+
1.0.3

vistos/src/gpo/fields.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ class Bill:
5555
PUBLISHER = 'publisher'
5656
COMMITTEES = 'committees'
5757
MEMBERS = 'members'
58+
TEXT = 'text'

vistos/src/gpo/govinfo.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ class GovInfoBillRecord(dict):
2121
"""A dict-like object for handling Congressional bill
2222
data returned from the GovInfo API"""
2323

24-
def __init__(self, bill_govinfo: dict):
24+
def __init__(self, bill_govinfo: dict, api_key: str):
2525
super().__init__()
26+
self._download_text = None
27+
2628
try:
2729
bill_version = bill_govinfo['billVersion']
2830
except KeyError:
@@ -78,6 +80,15 @@ def __init__(self, bill_govinfo: dict):
7880
except KeyError:
7981
self[_fields.Bill.MEMBERS] = None
8082

83+
self[_fields.Bill.TEXT] = None
84+
85+
try:
86+
text_url = bill_govinfo['download']['txtLink']
87+
self._download_text = \
88+
_create_download_bill_text_func(text_url, api_key)
89+
except (KeyError, ValueError):
90+
self._download_text = None
91+
8192
@property
8293
def bill_id(self) -> str:
8394
return self[_fields.Bill.BILL_ID]
@@ -138,6 +149,14 @@ def committees(self) -> List:
138149
def members(self) -> List:
139150
return self[_fields.Bill.MEMBERS]
140151

152+
@property
153+
def text(self) -> str:
154+
return self[_fields.Bill.TEXT]
155+
156+
def download_text(self):
157+
if self._download_text:
158+
self[_fields.Bill.TEXT] = self._download_text()
159+
141160

142161
class GovInfoCongressRecord(dict):
143162
"""A dict-like object for handling Congressional
@@ -224,6 +243,13 @@ def check_for_govinfo_bills(congress: int, api_key: str):
224243
return _bills_data_exists(api_key, congress)
225244

226245

246+
def _create_download_bill_text_func(text_url: str, api_key: str):
247+
"""Create callable for downloading bill text"""
248+
def download_bill_text():
249+
return _get_text_from(f'{text_url}?api_key={api_key}')
250+
return download_bill_text
251+
252+
227253
def _cdir_data_exists(api_key: str, congress: int) -> bool:
228254
"""Returns true if a cdir package is available for the given congress"""
229255
endpoint = \
@@ -441,7 +467,7 @@ def _get_text_concurrently():
441467
bill_records = []
442468
for package_text in package_text_data:
443469
package_json = _json.loads(package_text)
444-
bill_records.append(GovInfoBillRecord(package_json))
470+
bill_records.append(GovInfoBillRecord(package_json, api_key))
445471

446472
return bill_records
447473

0 commit comments

Comments
 (0)