Skip to content

Commit

Permalink
Get Fiscalnotes working
Browse files Browse the repository at this point in the history
  • Loading branch information
showerst committed Dec 11, 2024
1 parent 998e170 commit 9f7cd3b
Showing 1 changed file with 38 additions and 19 deletions.
57 changes: 38 additions & 19 deletions scrapers/al/bills.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
import lxml
import re
import datetime
import dateutil
import requests
from openstates.scrape import Scraper, Bill, VoteEvent
Expand Down Expand Up @@ -94,6 +93,9 @@ def scrape_bill_type(self, session: str, bill_type: str, offset: int, limit: int
instrumentType
instrumentSponsor
instrumentUrl
introducedUrl
engrossedUrl
enrolledUrl
companionInstrumentNbr
sessionType
sessionYear
Expand All @@ -114,11 +116,11 @@ def scrape_bill_type(self, session: str, bill_type: str, offset: int, limit: int
},
}

print(json_data)
# print(json_data)
page = requests.post(self.gql_url, headers=self.gql_headers, json=json_data)
page = json.loads(page.content)

print(page)
# print(page)

if page["data"]["instrumentOverviews"]["count"] < 1:
return
Expand Down Expand Up @@ -191,22 +193,22 @@ def scrape_bill_type(self, session: str, bill_type: str, offset: int, limit: int
yield from self.scrape_bill_type(session, bill_type, offset + 50, limit)

def scrape_versions(self, bill, row):
if row["IntroducedUrl"]:
if row["introducedUrl"]:
bill.add_version_link(
"Introduced",
url=row["IntroducedUrl"],
url=row["introducedUrl"],
media_type="application/pdf",
)
if row["EngrossedUrl"]:
if row["engrossedUrl"]:
bill.add_version_link(
"Engrossed",
url=row["EngrossedUrl"],
url=row["engrossedUrl"],
media_type="application/pdf",
)
if row["EnrolledUrl"]:
if row["enrolledUrl"]:
bill.add_version_link(
"Enrolled",
url=row["EnrolledUrl"],
url=row["enrolledUrl"],
media_type="application/pdf",
)

Expand Down Expand Up @@ -257,13 +259,11 @@ def scrape_act(self, bill: Bill, url: str, effective: str):
def scrape_actions(self, bill, bill_row):
bill_id = bill.identifier.replace(" ", "")

if bill_row["PrefiledDate"]:
action_date = datetime.datetime.strptime(
bill_row["PrefiledDate"], "%m/%d/%Y"
)
if bill_row["prefiledDate"]:
action_date = dateutil.parser.parse(bill_row["prefiledDate"])
action_date = self.tz.localize(action_date)
bill.add_action(
chamber=self.chamber_map[bill_row["Body"]],
chamber=self.chamber_map[bill_row["body"]],
description="Filed",
date=action_date,
classification="filing",
Expand Down Expand Up @@ -326,21 +326,40 @@ def scrape_actions(self, bill, bill_row):
def scrape_fiscal_notes(self, bill):
bill_id = bill.identifier.replace(" ", "")

print(self.session_type, self.session_year)

json_data = {
"query": "query fiscalNotes($instrumentNbr: String, $sessionType: String, $sessionYear: String){fiscalNotes(instrumentNbr:$instrumentNbr, sessionType:$sessionType, sessionYear: $sessionYear, ){ FiscalNoteDescription,FiscalNoteUrl,SortOrder }}",
"query": """
query {
fiscalNotes(
where: {sessionType: {eq: "2024 Regular Session"}, sessionYear: {eq: 2024}, instrumentNbr: {eq: "HB1"}}
)
{
data {
description
url
sortOrder
__typename
}
}
}
""",
"variables": {
"instrumentNbr": bill_id,
"sessionType": self.session_type,
"sessionYear": self.session_year,
"sessionYear": self.session_year + " Regular Session",
},
}

print(json_data)
page = requests.post(self.gql_url, headers=self.gql_headers, json=json_data)

print(page.content)
page = json.loads(page.content)
for row in page["data"]["fiscalNotes"]:
for row in page["data"]["fiscalNotes"]["data"]:
bill.add_document_link(
f"Fiscal Note: {row['FiscalNoteDescription']}",
row["FiscalNoteUrl"],
f"Fiscal Note: {row['description']}",
row["url"],
media_type="application/pdf",
on_duplicate="ignore",
)
Expand Down

0 comments on commit 9f7cd3b

Please sign in to comment.