summaryrefslogtreecommitdiff
path: root/backup-tc.py
diff options
context:
space:
mode:
Diffstat (limited to 'backup-tc.py')
-rw-r--r--backup-tc.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/backup-tc.py b/backup-tc.py
index 3e57340..1287ae1 100644
--- a/backup-tc.py
+++ b/backup-tc.py
@@ -27,9 +27,9 @@ for round_number in settings['RoundsNumbers']:
def fetch_file(url, output_dir, remote_file):
file_url = requests.compat.urljoin(url + '/', remote_file)
try:
+ r = requests.get(file_url)
+ r.raise_for_status()
with open(os.path.join(output_dir, remote_file), 'w') as output_file:
- r = requests.get(file_url)
- r.raise_for_status()
output_file.write(r.content)
print(file_url)
except Exception as e:
@@ -41,13 +41,15 @@ for remote_file in files_to_download:
files_to_download = set()
for round_json in round_jsons:
- round_data = json.load(open(os.path.join(output_dir, round_json)))
- for r in round_data['Results']:
- for s in r['Segments']:
- files_to_download.add('s%s-%d-%d-%d.json' % (
- r['TableFull'],
- round_data['Session'], round_data['Round'], s['Segment']
- ))
+ round_file = os.path.join(output_dir, round_json)
+ if os.path.exists(round_file):
+ round_data = json.load(open(round_file))
+ for r in round_data['Results']:
+ for s in r['Segments']:
+ files_to_download.add('s%s-%d-%d-%d.json' % (
+ r['TableFull'],
+ round_data['Session'], round_data['Round'], s['Segment']
+ ))
for remote_file in files_to_download:
fetch_file(url, output_dir, remote_file)