-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_user.py
executable file
·90 lines (77 loc) · 1.83 KB
/
add_user.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import getpass
import os
import bcrypt
import sys
from quizitemfinder.io import ensure_dir
username = input('username to add: ')
try:
os.makedirs("./score_data/{}/my_courses/106-2/ENG-101".format(username)) # examples
except:
print('user already exists')
sys.exit(1)
try:
os.makedirs("./users")
except:
pass
# example
with open("./score_data/{}/my_courses/106-2/ENG-101/roster.csv".format(username), "w+") as myfile:
roster = """ID,NAME,EMAIL
10001,Roger,[email protected]
1002,Jenny,[email protected]
1003,John,[email protected]
1004,Dovie ,*
1005,Daniel,*
1006,Rossana ,*
1007,Gretchen ,*
1008,Margery ,*
1009,Keva ,*
1010,Elliot ,*
1011,Shay ,*
1012,Eleanor ,*
1013,Dorthea ,*
1014,Elvie ,*
1015,Gerard ,*
1016,Cassie ,*
1017,Lula ,*
1018,Lady ,*
1019,Walter ,*
1020,Delores ,*
1021,Stanley ,*
1022,Cheree ,*
1023,Jefferson ,*
1024,Janis ,*
1025,Ressie ,*
1026,Gretta ,*
1027,Noah ,*
1028,Chanelle,*
1029,Nguyet ,*
1030,Sharmaine ,*
1031,Cecila ,*
1032,Stacia ,*
1033,Latia ,*
1034,Carry ,*
1035,Carmelo ,*
1036,Franklin ,*
1037,Riley ,*
1038,Lesha ,*
1039,Lauran ,*
1040,Yoshie ,*
1041,Mitsue ,*
1042,Wilda ,*
1043,Elisha ,*
1044,Carisa ,*
1045,Camellia ,*
1046,Jeanie ,*
1047,Kathryn ,*
1048,Loura ,*
"""
myfile.write(roster)
#if( not os.path.isfile("./users/users") ):
# ensure_dir("./users")
# open("./users/users", "w+")
password = getpass.getpass('password for user: ').encode('utf-8')
password_hashed = bcrypt.hashpw(password, bcrypt.gensalt()).decode("utf-8", "strict")
user_line = "{}:{}\n".format(username, password_hashed)
with open("./users/users", "a+") as myfile:
myfile.write(user_line)
print("\n put a file called 'roster.csv' into ./score_data/{}/my_courses/106-2/ENG-101 to set up your class.\n".format(username))