summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backup-tc.py53
-rwxr-xr-xbackup-tc.sh27
2 files changed, 80 insertions, 0 deletions
diff --git a/backup-tc.py b/backup-tc.py
new file mode 100644
index 0000000..3e57340
--- /dev/null
+++ b/backup-tc.py
@@ -0,0 +1,53 @@
+import json, os, sys
+import requests
+
+url = sys.argv[1]
+output_dir = sys.argv[2]
+
+settings = json.load(open(os.path.join(output_dir, 'settings.json')))
+
+files_to_download = set()
+
+for board in settings['BoardsScoringGroups']:
+ for group in board['Value']:
+ for prefix in ['d', 'sg']:
+ files_to_download.add('%s%d-%d.json' % (prefix, board['Key'], group))
+ files_to_download.add('p%d.html' % (board['Key']))
+
+round_jsons = set()
+
+for round_number in settings['RoundsNumbers']:
+ round_results = 'o%d-%d.json' % (
+ round_number / 1000, round_number % 1000)
+ files_to_download.add(round_results)
+ round_jsons.add(round_results)
+ for participant in settings['ParticipantNumers']:
+ files_to_download.add('h%d.json' % (participant))
+
+def fetch_file(url, output_dir, remote_file):
+ file_url = requests.compat.urljoin(url + '/', remote_file)
+ try:
+ 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:
+ print 'WARNING: %s' % (e)
+
+for remote_file in files_to_download:
+ fetch_file(url, output_dir, remote_file)
+
+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']
+ ))
+
+for remote_file in files_to_download:
+ fetch_file(url, output_dir, remote_file)
diff --git a/backup-tc.sh b/backup-tc.sh
new file mode 100755
index 0000000..79f235c
--- /dev/null
+++ b/backup-tc.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+URL=$1
+[[ $URL =~ (/?(index\.html)?(\#.*)?$) ]] && \
+ URL=${URL//$BASH_REMATCH/}
+
+OUTPUT_DIR="$2"
+if [ -z "$OUTPUT_DIR" ]
+then
+ OUTPUT_DIR="."
+fi
+
+mkdir -p "$OUTPUT_DIR"
+
+wget --mirror --page-requisites --no-parent --no-directories --directory-prefix="$OUTPUT_DIR" "$URL/"
+
+for FILE in settings.json results.json vp.json butler.json cs.json
+do
+ wget -N --directory-prefix="$OUTPUT_DIR" "$URL/$FILE"
+done
+
+for LANG in pl en
+do
+ wget -N --directory-prefix="$OUTPUT_DIR/language" "$URL/language/$LANG.json"
+done
+
+python backup-tc.py "$URL" "$OUTPUT_DIR"