aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTudor Roman2019-10-07 18:43:08 +0300
committerTudor Roman2019-10-07 18:43:08 +0300
commit6a21ae2e5903a90375b5e420a72b61310a0906eb (patch)
tree9dc019b17ea8a5b5bb453d87830f720b97c4c103
parent598a52845e9ba19705e8f26ece6f5fcf0775f9e5 (diff)
downloadrmi_scripts-6a21ae2e5903a90375b5e420a72b61310a0906eb.tar.gz
rmi_scripts-6a21ae2e5903a90375b5e420a72b61310a0906eb.zip
generate password for each participation
-rwxr-xr-xadd_participations18
1 files changed, 15 insertions, 3 deletions
diff --git a/add_participations b/add_participations
index 32c10e5..67937b7 100755
--- a/add_participations
+++ b/add_participations
@@ -10,15 +10,27 @@
import csv
import sys
+import binascii
+import os
from subprocess import call
-if len(sys.argv) != 3:
- print("Usage: add_participations <csv_file> <contest_id>")
+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:
- call(['cmsAddParticipation', '-c', contest_id, '-t', row['team_id'], row['username']])
+ 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)