aboutsummaryrefslogtreecommitdiff
path: root/add_participations
blob: 67937b7d08b4348f7f8ac280f91acb960c44d73b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
#
# Adds participations into CMS
#
# Made by Tudor Roman, public domain
#
# This script expects as its first argument a table generated by add_users.
# The second argument is the id of the contest.
#

import csv
import sys
import binascii
import os
from subprocess import call

if len(sys.argv) != 4:
    print("Usage: add_participations <csv_file> <contest_id> <out_file>")
    sys.exit(1)

contest_id = sys.argv[2]
User = namedtuple('User', 'username password')
users = []

with open(sys.argv[1]) as file:
    reader = csv.DictReader(file, delimiter=',')
    for row in reader:
        password = binascii.b2a_hex(os.urandom(6)).decode('ascii')
        call(['cmsAddParticipation', '-c', contest_id, '-t', row['team_id'], '-p', password, row['username']])
        users.append(User(row['username'], password))

with open(sys.argv[3]) as out_file:
    writer = csv.writer(out_file)
    writer.writerow(['username', 'password'])
    for u in users:
        writer.writerow(u)