Skip to content

Commit 3e05c3b

Browse files
committed
DM-220: Make downloads efficient again
1 parent 82f13e4 commit 3e05c3b

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

dms_datastore/download_ncro_cnra.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,10 @@ def download_ncro_inventory(dest, cache=True):
4747
logger.info(f"Downloading inventory for NCRO attempt #{attempt}")
4848
try:
4949
response = session.get(
50-
url, verify=False, stream=True, headers={"User-Agent": "Mozilla/6.0"}
50+
url, verify=False, headers={"User-Agent": "Mozilla/6.0"}
5151
)
5252
response.raise_for_status()
53-
for chunk in response.iter_lines(chunk_size=1024): # Iterate over lines
54-
if chunk: # Filter out keep-alive new chunks
55-
inventory_html += chunk.decode("utf-8") + "\n"
56-
57-
# response.encoding = 'UTF-8'
58-
# inventory_html = response.content.decode('utf-8')
53+
inventory_html = response.text
5954
fio = io.StringIO(inventory_html)
6055

6156
idf = pd.read_csv(

dms_datastore/download_nwis.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,23 +239,20 @@ def download_station(
239239
else:
240240
station_query = station_query_base
241241
logger.info(f"USGS Query for ({station},{paramname}): {station_query}")
242-
max_attempt = 10
242+
max_attempt = 3
243243
session = requests.Session()
244244
station_html = ""
245245
found = False
246246
for attempt in range(1, (max_attempt + 1)):
247-
logger.debug(f"attempt: {attempt} variable {int(param):05}")
247+
logger.debug(f"attempt: {attempt} variable {int(param):05}, {station}, {agency_id}")
248248
try:
249249
response = session.get(
250250
station_query,
251-
stream=True,
252251
headers={"User-Agent": "Mozilla/6.0"},
253-
timeout=15,
252+
timeout=75,
254253
)
255254
response.raise_for_status()
256-
for chunk in response.iter_lines(chunk_size=4096): # Iterate over lines
257-
if chunk: # Filter out keep-alive new chunks
258-
station_html += chunk.decode() + "\n"
255+
station_html = response.text
259256
logger.debug("Request successful, got text")
260257
break
261258
except Exception as e:

0 commit comments

Comments
 (0)