summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2020-02-07 03:05:26 +0100
committeremkael <emkael@tlen.pl>2020-02-07 03:05:26 +0100
commit849d6cca6992b38d0fabc178654be5619ce12e95 (patch)
tree1640ece4d70b1d6e9e63852360c57f71c8fd7ad3
parent5e0c5146601fad2c6e499fc65531c52c6271e839 (diff)
Download segment data only when round data is availableHEADmaster
-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)