Fixed bug in puller causing bailout during connection error
This commit is contained in:
parent
a47c8b95d0
commit
133a4f563c
1 changed files with 48 additions and 41 deletions
|
|
@ -15,20 +15,20 @@ directory_url = r"https://data.ngdc.noaa.gov/platforms/solar-space-observing-sat
|
||||||
stored_images_dir = r"..\Data"
|
stored_images_dir = r"..\Data"
|
||||||
# directory_url = r"https://data.ngdc.noaa.gov/platforms/solar-space-observing-satellites/goes/goes16/l2/data/suvi-l2-ci094/"
|
# directory_url = r"https://data.ngdc.noaa.gov/platforms/solar-space-observing-satellites/goes/goes16/l2/data/suvi-l2-ci094/"
|
||||||
# stored_images_dir = r"Z:\NOAA GOES Data\Data\goes16\l2\suvi-l2-ci094"
|
# stored_images_dir = r"Z:\NOAA GOES Data\Data\goes16\l2\suvi-l2-ci094"
|
||||||
ignore_folder_names = ["l1b", "goes17", "2017", "2018", "2019", "2020", "2021", "2022"]
|
ignore_folder_names = ["l1b", "goes17", "2017", "2018", "2019", "2020"]
|
||||||
file_database_path = r"..\file_database.json"
|
file_database_path = r"..\file_database.json"
|
||||||
fetch_interval = 60*60
|
fetch_interval = 0 # 60*60
|
||||||
nworkers = 16
|
nworkers = 8
|
||||||
randomize_order = True
|
randomize_order = False
|
||||||
|
|
||||||
def recursive_find_links(url, attempt_count = 3, randomize_order = True):
|
def recursive_find_links(url, attempt_count = 3, randomize_order = True):
|
||||||
links_regex_pattern = r'(?<=<a href=")([^ ?:]*)(?=">.*\d{4}-\d{2}-\d{2} \d{2}:\d{2})' # Find href links that do not contain question marks or whitespace
|
links_regex_pattern = r'(?<=<a href=")([^ ?:]*)(?=">.*\d{4}-\d{2}-\d{2} \d{2}:\d{2})' # Find href links that do not contain question marks or whitespace
|
||||||
times_regex_pattern = r'(?<=<td align="right">)(\d{4}-\d{2}-\d{2} \d{2}:\d{2})(?= )' # Find timestamps in UTC in the format YYYY-MM-DD HH:mm
|
times_regex_pattern = r'(?<=<td align="right">)(\d{4}-\d{2}-\d{2} \d{2}:\d{2})(?= )' # Find timestamps in UTC in the format YYYY-MM-DD HH:mm
|
||||||
with urllib.request.urlopen(url) as response:
|
|
||||||
attempts = 0
|
attempts = 0
|
||||||
html_content = None
|
html_content = None
|
||||||
while attempts < attempt_count:
|
while attempts < attempt_count:
|
||||||
try:
|
try:
|
||||||
|
with urllib.request.urlopen(url) as response:
|
||||||
html_content = response.read().decode('utf-8')
|
html_content = response.read().decode('utf-8')
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -61,7 +61,7 @@ def recursive_find_links(url, attempt_count = 3, randomize_order = True):
|
||||||
if _link.split(r"/")[-2] in ignore_folder_names:
|
if _link.split(r"/")[-2] in ignore_folder_names:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
yield from recursive_find_links(urllib.parse.urljoin(url,_link), randomize_order)
|
yield from recursive_find_links(urllib.parse.urljoin(url,_link), attempt_count, randomize_order)
|
||||||
else:
|
else:
|
||||||
yield urllib.parse.urljoin(url,_link), _time
|
yield urllib.parse.urljoin(url,_link), _time
|
||||||
|
|
||||||
|
|
@ -120,7 +120,7 @@ if __name__ == "__main__":
|
||||||
already_had_image_count = 0
|
already_had_image_count = 0
|
||||||
failed_image_count = 0
|
failed_image_count = 0
|
||||||
urllen = len(directory_url)
|
urllen = len(directory_url)
|
||||||
for l, t in tqdm.tqdm(recursive_find_links(directory_url, randomize_order), desc="Downloading files"):
|
for l, t in tqdm.tqdm(recursive_find_links(directory_url, randomize_order = randomize_order), desc="Downloading files"):
|
||||||
# Collect completed jobs and record completion status
|
# Collect completed jobs and record completion status
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
|
@ -152,7 +152,14 @@ if __name__ == "__main__":
|
||||||
with open(file_database_path, 'w') as f:
|
with open(file_database_path, 'w') as f:
|
||||||
f.write(json.dumps(file_info_cache))
|
f.write(json.dumps(file_info_cache))
|
||||||
print(f"Downloaded {fetched_image_count} | Already had {already_had_image_count} | Failed {failed_image_count}")
|
print(f"Downloaded {fetched_image_count} | Already had {already_had_image_count} | Failed {failed_image_count}")
|
||||||
|
if fetch_interval > 0:
|
||||||
|
print(f"Run complete!, sleeping for {fetch_interval} seconds.")
|
||||||
|
with open(file_database_path, 'w') as f:
|
||||||
|
f.write(json.dumps(file_info_cache))
|
||||||
time.sleep(fetch_interval)
|
time.sleep(fetch_interval)
|
||||||
|
else:
|
||||||
|
print("Run complete!, exiting...")
|
||||||
|
break
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("Saving file database and shutting down.")
|
print("Saving file database and shutting down.")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue