From 28ad1462048fbde98e046427a1b9a4da7b8d5267 Mon Sep 17 00:00:00 2001 From: Jan Schaumann Date: Tue, 25 Oct 2022 15:44:32 -0400 Subject: [PATCH 1/2] tell the user why we couldn't parse the config This is useful when e.g., the user edits the config.json.example file instead of copying to config.json and then doesn't understand why the program can't parse the json: with this change, the program will helpfully tell the use that it couldn't find the file "config.json". --- download.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/download.py b/download.py index 976e68d..84b8c1d 100644 --- a/download.py +++ b/download.py @@ -19,8 +19,8 @@ config_file = open("config.json", "r") config = json.load(config_file) config_file.close() -except: - sys.stderr.write("Error loading config.json file.\n") +except Exception as e: + sys.stderr.write("Error loading config.json file: %s\n" % str(e)) exit(1) # The config.json file must contain the following data: From 6c2f274c2484da9fc525f87d6cab143a9e4eba97 Mon Sep 17 00:00:00 2001 From: Jan Schaumann Date: Wed, 26 Apr 2023 23:01:01 -0400 Subject: [PATCH 2/2] don't overwrite existing files --- download.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/download.py b/download.py index 84b8c1d..814a00e 100644 --- a/download.py +++ b/download.py @@ -2,6 +2,7 @@ import sys import cgi import os +import os.path import datetime from do_authentication import authenticate @@ -19,8 +20,8 @@ config_file = open("config.json", "r") config = json.load(config_file) config_file.close() -except Exception as e: - sys.stderr.write("Error loading config.json file: %s\n" % str(e)) +except: + sys.stderr.write("Error loading config.json file.\n") exit(1) # The config.json file must contain the following data: @@ -118,9 +119,10 @@ def download_one_zone(url, output_directory): # This is where the zone file will be saved path = '{0}/{1}'.format(output_directory, filename) - with open(path, 'wb') as f: - for chunk in download_zone_response.iter_content(1024): - f.write(chunk) + if not os.path.isfile(path): + with open(path, 'wb') as f: + for chunk in download_zone_response.iter_content(1024): + f.write(chunk) print("{0}: Completed downloading zone to file {1}".format(str(datetime.datetime.now()), path))