Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MT: add bill versions for LC draft versions #5130

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions scrapers/mt/bills.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def scrape_list_page(self, session, page_num: int):
self.scrape_fiscal_note(
bill, row["billType"]["code"], row["billNumber"]
)
self.scrape_lc_versions(bill, row["draft"]["draftNumber"])

if row["sponsorId"]:
for legislator in self.legislators:
Expand Down Expand Up @@ -398,3 +399,23 @@ def scrape_versions(self, bill: Bill, bill_type: str, bill_number: str):
media_type="application/pdf",
on_duplicate="ignore",
)

def scrape_lc_versions(self, bill: Bill, lc_number: str):
lc_docs_url = f"https://api.legmt.gov/docs/v1/documents/getBillLcs?legislatureOrdinal={self.session_ord}&sessionOrdinal={self.mt_session_id}&lcnumber={lc_number}"
try:
response = self.get(lc_docs_url).json()
except scrapelib.HTTPError:
# no data = 404 instead of empty json
return

# TODO: this url returns binary data without the correct content type header,
# we could POST to https://api.legmt.gov/docs/v1/documents/shortPdfUrl?documentId=2710 and get back a better
# GET url, but is that worth 5x the requests?
for doc_row in response:
doc_url = f"https://api.legmt.gov/docs/v1/documents/getContent?documentId={str(doc_row['id'])}"
bill.add_version_link(
doc_row["fileName"],
doc_url,
media_type="application/pdf",
on_duplicate="ignore",
)
Loading