-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_users
More file actions
executable file
·44 lines (38 loc) · 1.44 KB
/
add_users
File metadata and controls
executable file
·44 lines (38 loc) · 1.44 KB
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
37
38
39
40
41
42
43
#!/usr/bin/env python3
#
# Adds users into CMS and generate a nice table
#
# Made by Tudor Roman, public domain
#
# This script expects as its first argument a csv table with header and two columns, name and id
# like the add_teams script. The second argument is the output csv.
#
import csv
import sys
import unicodedata
import os
import binascii
from collections import namedtuple
from subprocess import call
def to_ascii(s):
return unicodedata.normalize('NFKD', s).encode('ascii', 'ignore').decode('ascii')
if len(sys.argv) != 3:
print("Usage: add_users <csv_in_file> <csv_out_file>")
sys.exit(1)
User = namedtuple('User', 'first_name last_name username password team_id')
users = []
with open(sys.argv[1]) as in_file:
reader = csv.DictReader(in_file, delimiter=',')
for row in reader:
first_name = row['Prenume']
last_name = row['Nume']
username = (to_ascii(last_name) + '-' + binascii.b2a_hex(os.urandom(15))[-3:].decode('ascii')).lower()
password = binascii.b2a_hex(os.urandom(6)).decode('ascii')
users.append(User(first_name, last_name, username, password, row['team_id']))
with open(sys.argv[2], 'w') as out_file:
writer = csv.writer(out_file)
writer.writerow(['first_name', 'last_name', 'username', 'password', 'team_id'])
for u in users:
writer.writerow(u)
for u in users:
call(['cmsAddUser', '-p', u.password, u.first_name, u.last_name, u.username])