Skip to content

Commit 00a9205

Browse files
Merge pull request #5688 from openstates/de-bills-try-skipping-bills-on-fetch-failure
DE: experiment with skipping bills when core fetch fails
2 parents d703ad0 + 01efa04 commit 00a9205

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

scrapers/de/bills.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
from .actions import Categorizer
1313

1414

15+
class FailedBillFetch:
16+
def __init__(self, bill_id, fetch_type):
17+
self.bill_id = bill_id
18+
self.fetch_type = fetch_type
19+
20+
1521
class DEBillScraper(Scraper, LXMLMixin):
1622
verify = False
1723

@@ -115,7 +121,7 @@ def scrape(self, session=None, start_page=1, end_page=None):
115121
page_number=page_number,
116122
per_page=per_page,
117123
)
118-
page = self.decode_and_retry_request("post_search", post_search)
124+
page = self.decode_and_retry_request("post_search", post_search, retries=6)
119125
if not page["Data"]:
120126
self.info("Found no more bills in pagination")
121127
break
@@ -147,6 +153,14 @@ def filter_bills(self, items):
147153
yield bill
148154
continue
149155

156+
# The generator also includes FailedBill objects representing failures to fetch
157+
# we want to log these out at the end, so putting this logic here in filter_bills()
158+
if isinstance(bill, FailedBillFetch):
159+
self.logger.warning(
160+
f"Failed to fetch bill {bill.bill_id} on fetch {bill.fetch_type}"
161+
)
162+
continue
163+
150164
if (
151165
bill.identifier in bills
152166
and (
@@ -219,7 +233,13 @@ def scrape_bill(self, row, session):
219233
html_url = f"https://legis.delaware.gov/BillDetail?LegislationId={row['LegislationId']}"
220234
bill.add_source(html_url, note="text/html")
221235

222-
html = self.lxmlize(html_url, verify=False)
236+
try:
237+
html = self.lxmlize(html_url, verify=False)
238+
except: # noqa: E722
239+
# Collecting bills we had to skip because of failure to fetch
240+
failure = FailedBillFetch(bill_id, "fetch_bill_page")
241+
yield failure
242+
return
223243

224244
additional_sponsors = html.xpath(
225245
'//label[text()="Additional Sponsor(s):"]/following-sibling::div/a/@href'
@@ -268,7 +288,13 @@ def scrape_bill(self, row, session):
268288
for fiscal in fiscals:
269289
self.scrape_fiscal_note(bill, fiscal)
270290

271-
self.scrape_actions(bill, row["LegislationId"])
291+
try:
292+
self.scrape_actions(bill, row["LegislationId"])
293+
except: # noqa: E722
294+
# Collecting bills we had to skip because of failure to fetch
295+
failure = FailedBillFetch(bill_id, "fetch_bill_page")
296+
yield failure
297+
return
272298

273299
if row["HasAmendments"] is True:
274300
self.scrape_amendments(bill, row["LegislationId"])

0 commit comments

Comments
 (0)