Skip to content

Commit c7aeb11

Browse files
committed
[contest] get_contest_id: When running with given contest_id, check whether it exists
1 parent 19d1395 commit c7aeb11

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

bin/contest.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,19 @@ def get_api():
5353

5454

5555
def get_contest_id():
56-
if config.args.contest_id:
57-
return config.args.contest_id
58-
if 'contest_id' in contest_yaml():
59-
return contest_yaml()['contest_id']
56+
contest_id = (
57+
config.args.contest_id
58+
if config.args.contest_id
59+
else contest_yaml()['contest_id'] if 'contest_id' in contest_yaml() else None
60+
)
6061
contests = get_contests()
62+
if contest_id is not None:
63+
if contest_id not in {c['id'] for c in contests}:
64+
for contest in contests:
65+
log(f'{contest["id"]}: {contest["name"]}')
66+
fatal(f'Contest {contest_id} not found.')
67+
else:
68+
return contest_id
6169
if len(contests) > 1:
6270
for contest in contests:
6371
log(f'{contest["id"]}: {contest["name"]}')

0 commit comments

Comments
 (0)