|
12 | 12 | from .actions import Categorizer |
13 | 13 |
|
14 | 14 |
|
| 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 | + |
15 | 21 | class DEBillScraper(Scraper, LXMLMixin): |
16 | 22 | verify = False |
17 | 23 |
|
@@ -115,7 +121,7 @@ def scrape(self, session=None, start_page=1, end_page=None): |
115 | 121 | page_number=page_number, |
116 | 122 | per_page=per_page, |
117 | 123 | ) |
118 | | - page = self.decode_and_retry_request("post_search", post_search) |
| 124 | + page = self.decode_and_retry_request("post_search", post_search, retries=6) |
119 | 125 | if not page["Data"]: |
120 | 126 | self.info("Found no more bills in pagination") |
121 | 127 | break |
@@ -147,6 +153,14 @@ def filter_bills(self, items): |
147 | 153 | yield bill |
148 | 154 | continue |
149 | 155 |
|
| 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 | + |
150 | 164 | if ( |
151 | 165 | bill.identifier in bills |
152 | 166 | and ( |
@@ -219,7 +233,13 @@ def scrape_bill(self, row, session): |
219 | 233 | html_url = f"https://legis.delaware.gov/BillDetail?LegislationId={row['LegislationId']}" |
220 | 234 | bill.add_source(html_url, note="text/html") |
221 | 235 |
|
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 |
223 | 243 |
|
224 | 244 | additional_sponsors = html.xpath( |
225 | 245 | '//label[text()="Additional Sponsor(s):"]/following-sibling::div/a/@href' |
@@ -268,7 +288,13 @@ def scrape_bill(self, row, session): |
268 | 288 | for fiscal in fiscals: |
269 | 289 | self.scrape_fiscal_note(bill, fiscal) |
270 | 290 |
|
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 |
272 | 298 |
|
273 | 299 | if row["HasAmendments"] is True: |
274 | 300 | self.scrape_amendments(bill, row["LegislationId"]) |
|
0 commit comments