@@ -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
142161class 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+
227253def _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