forked from DOMjudge/domjudge
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
124 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#!/usr/bin/env python3 | ||
|
||
''' | ||
export-contest -- Convenience script to export a contest (including metadata, | ||
teams and problems) from the command line. Defaults to using the CLI interface; | ||
Specify a DOMjudge API URL as to use that. | ||
Reads credentials from ~/.netrc when using the API. | ||
Part of the DOMjudge Programming Contest Jury System and licensed | ||
under the GNU GPL. See README and COPYING for details. | ||
''' | ||
|
||
import json | ||
import sys | ||
# from concurrent.futures import ThreadPoolExecutor | ||
# from multiprocessing import Pool | ||
from pathlib import Path | ||
|
||
sys.path.append('@domserver_libdir@') | ||
import dj_utils | ||
|
||
cid = None | ||
webappdir = '@domserver_webappdir@' | ||
|
||
|
||
def usage(): | ||
print(f'Usage: {sys.argv[0]} [<domjudge-api-url>]') | ||
exit(1) | ||
|
||
|
||
def api_to_file(endpoint: str, filename: str): | ||
print(f"Fetching '{endpoint}' to '{filename}'") | ||
data = dj_utils.do_api_request(endpoint, decode=False) | ||
with open(filename, 'w') as f: | ||
f.write(data) | ||
|
||
return data | ||
|
||
|
||
def download_submission(submission): | ||
d = f'submissions/{submission["id"]}' | ||
Path(d).mkdir(parents=True, exist_ok=True) | ||
for f in submission['files']: | ||
if f['mime'] == 'application/zip': | ||
print(f"Downloading '{f['href']}'") | ||
data = dj_utils.do_api_request(f['href'], decode=False) | ||
with open(f'{d}/files.zip', 'w') as f: | ||
f.write(data) | ||
break | ||
|
||
|
||
if len(sys.argv) == 1: | ||
dj_utils.domjudge_webapp_folder_or_api_url = webappdir | ||
elif len(sys.argv) == 2: | ||
dj_utils.domjudge_webapp_folder_or_api_url = sys.argv[1] | ||
else: | ||
usage() | ||
|
||
|
||
user_data = dj_utils.do_api_request('user') | ||
if 'admin' not in user_data['roles']: | ||
print('Your user does not have the \'admin\' role, can not export.') | ||
exit(1) | ||
|
||
|
||
contest_id = 'wf48_systest2' | ||
|
||
for endpoint in [ | ||
'accounts', | ||
'awards', | ||
'balloons', | ||
'clarifications', | ||
'groups', | ||
'judgements', | ||
'languages', | ||
'organizations', | ||
'problems', | ||
'runs', | ||
'scoreboard', | ||
'submissions', | ||
'teams', | ||
]: | ||
data = api_to_file(f'contests/{contest_id}/{endpoint}', f'{endpoint}.json') | ||
if endpoint == 'submissions': | ||
submissions = json.loads(data) | ||
|
||
api_to_file(f'contests/{contest_id}/event-feed?stream=false', 'event-feed.ndjson') | ||
|
||
|
||
for submission in submissions: | ||
download_submission(submission) | ||
|
||
# with Pool(processes=10) as pool: | ||
# result = pool.map_async(download_submission, submissions) | ||
# | ||
# print(result) | ||
# result.wait() | ||
|
||
# with ThreadPoolExecutor(20) as executor: | ||
# for submission in submissions: | ||
# executor.submit(download_submission, submission) |