warn-scraper 1.2.155.dev0__py3-none-any.whl → 1.2.156.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
warn/utils.py CHANGED
@@ -59,6 +59,8 @@ def fetch_if_not_cached(filename, url, **kwargs):
59
59
  url: The URL from which the file may be downloaded.
60
60
  Notes: Should this even be in utils vs. cache? Should it exist?
61
61
  """
62
+ if "timeout" not in kwargs:
63
+ kwargs["timeout"] = 120
62
64
  create_directory(Path(filename), is_file=True)
63
65
  if not os.path.exists(filename):
64
66
  logger.debug(f"Fetching {filename} from {url}")
@@ -81,6 +83,8 @@ def save_if_good_url(filename, url, **kwargs):
81
83
  Notes: Should this even be in utils vs. cache? Should it exist?
82
84
  """
83
85
  create_directory(Path(filename), is_file=True)
86
+ if "timeout" not in kwargs:
87
+ kwargs["timeout"] = 120
84
88
  response = requests.get(url, **kwargs)
85
89
  if not response.ok:
86
90
  logger.error(f"URL {url} fetch failed with {response.status_code}")
@@ -96,7 +100,7 @@ def save_if_good_url(filename, url, **kwargs):
96
100
  return success_flag, content
97
101
 
98
102
 
99
- def get_with_zyte(url, json_extras=None):
103
+ def get_with_zyte(url, json_extras=None, **kwargs):
100
104
  """Use Zyte as a proxy server to retrieve data not available without it.
101
105
 
102
106
  Args:
@@ -119,6 +123,9 @@ def get_with_zyte(url, json_extras=None):
119
123
  )
120
124
  return (None, None)
121
125
 
126
+ if "timeout" not in kwargs:
127
+ kwargs["timeout"] = 120
128
+
122
129
  myjson = {
123
130
  "url": url,
124
131
  "httpResponseBody": True,
@@ -129,7 +136,10 @@ def get_with_zyte(url, json_extras=None):
129
136
  myjson[item] = json_extras[item]
130
137
 
131
138
  api_response = requests.post(
132
- "https://api.zyte.com/v1/extract", auth=(zyte_api_key, ""), json=myjson
139
+ "https://api.zyte.com/v1/extract",
140
+ auth=(zyte_api_key, ""),
141
+ json=myjson,
142
+ **kwargs,
133
143
  )
134
144
 
135
145
  if not api_response.ok:
@@ -150,7 +160,7 @@ def get_with_zyte(url, json_extras=None):
150
160
  return (returnbin, returntext)
151
161
 
152
162
 
153
- def post_with_zyte(url, payload):
163
+ def post_with_zyte(url, payload, **kwargs):
154
164
  """Use Zyte as a proxy server to retrieve data not available without it.
155
165
 
156
166
  Args:
@@ -175,6 +185,9 @@ def post_with_zyte(url, payload):
175
185
  )
176
186
  return (None, None)
177
187
 
188
+ if "timeout" not in kwargs:
189
+ kwargs["timeout"] = 120
190
+
178
191
  if isinstance(payload, dict):
179
192
  payload = json.dumps(payload)
180
193
 
@@ -191,6 +204,7 @@ def post_with_zyte(url, payload):
191
204
  "httpResponseBody": True,
192
205
  "followRedirect": True,
193
206
  },
207
+ **kwargs,
194
208
  )
195
209
 
196
210
  if not api_response.ok:
@@ -326,6 +340,9 @@ def get_url(
326
340
  kwargs["headers"] = {}
327
341
  kwargs["headers"]["User-Agent"] = user_agent
328
342
 
343
+ if "timeout" not in kwargs:
344
+ kwargs["timeout"] = 120
345
+
329
346
  # Go get it
330
347
  if session is not None:
331
348
  logger.debug(f"Requesting with session {session}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: warn-scraper
3
- Version: 1.2.155.dev0
3
+ Version: 1.2.156.dev0
4
4
  Summary: Command-line interface for downloading WARN Act notices of qualified plant closings and mass layoffs from state government websites
5
5
  Author-email: Big Local News <biglocalnews@stanford.edu>
6
6
  License-Expression: Apache-2.0
@@ -2,7 +2,7 @@ warn/__init__.py,sha256=A07JFY1TyaPtVIndBa7IvTk13DETqIkLgRdk0A-MCoE,85
2
2
  warn/cache.py,sha256=QBSHycchvRTkOQfHptOtZeTYiPgLP383jS8MTiGln_c,5969
3
3
  warn/cli.py,sha256=ZqyJwICdHFkn2hEgbArj_upbElR9-TSDlYDqyEGeexE,2019
4
4
  warn/runner.py,sha256=oeGRybGwpnkQKlPzRMlKxhsDt1GN4PZoX-vUwrsPgos,1894
5
- warn/utils.py,sha256=h1V5IISj9c2REtNnGctp0JqVjCi_Mi0r_FlvzNlrKb0,13093
5
+ warn/utils.py,sha256=MTqbzF4h_TlrtBWqH4pEVA-X8yfw6b6ObafSGkqxKb4,13489
6
6
  warn/pdfrodent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  warn/pdfrodent/pdfrodent.py,sha256=S2LXkKOdP0Jqzcg10hzGijTu83TMS72DzZqQceslJ70,14914
8
8
  warn/platforms/__init__.py,sha256=wIZRDf4tbTuC8oKM4ZrTAtwNgbtMQGzPXMwDYCFyrog,81
@@ -54,9 +54,9 @@ warn/scrapers/va.py,sha256=7Nle7qL0VNPiE653XyaP9HQqSfuJFDRr2kEkjOqLvFM,11269
54
54
  warn/scrapers/vt.py,sha256=d-bo4WK2hkrk4BhCCmLpEovcoZltlvdIUB6O0uaMx5A,1186
55
55
  warn/scrapers/wa.py,sha256=UXdVtHZo_a-XfoiyOooTRfTb9W3PErSZdKca6SRORgs,4282
56
56
  warn/scrapers/wi.py,sha256=ClEzXkwZbop0W4fkQgsb5oHAPUrb4luUPGV-jOKwkcg,4855
57
- warn_scraper-1.2.155.dev0.dist-info/licenses/LICENSE,sha256=ZV-QHyqPwyMuwuj0lI05JeSjV1NyzVEk8Yeu7FPtYS0,585
58
- warn_scraper-1.2.155.dev0.dist-info/METADATA,sha256=Vz4NRjIMPAx1mNm6337Va3PAEhD4Zd4VTNeiGBumCG0,1780
59
- warn_scraper-1.2.155.dev0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
60
- warn_scraper-1.2.155.dev0.dist-info/entry_points.txt,sha256=poh_oSweObGlBSs1_2qZmnTodlOYD0KfO7-h7W2UQIw,47
61
- warn_scraper-1.2.155.dev0.dist-info/top_level.txt,sha256=dZfms6N3kqVXufiPOo7YqOrAcUtYfNH_oyGvYUk9FB4,5
62
- warn_scraper-1.2.155.dev0.dist-info/RECORD,,
57
+ warn_scraper-1.2.156.dev0.dist-info/licenses/LICENSE,sha256=ZV-QHyqPwyMuwuj0lI05JeSjV1NyzVEk8Yeu7FPtYS0,585
58
+ warn_scraper-1.2.156.dev0.dist-info/METADATA,sha256=3ZYa-9I2ULmcbnva6Uyjqw5XNgxv4Lc5LetTtWT0w_s,1780
59
+ warn_scraper-1.2.156.dev0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
60
+ warn_scraper-1.2.156.dev0.dist-info/entry_points.txt,sha256=poh_oSweObGlBSs1_2qZmnTodlOYD0KfO7-h7W2UQIw,47
61
+ warn_scraper-1.2.156.dev0.dist-info/top_level.txt,sha256=dZfms6N3kqVXufiPOo7YqOrAcUtYfNH_oyGvYUk9FB4,5
62
+ warn_scraper-1.2.156.dev0.dist-info/RECORD,,