-
Notifications
You must be signed in to change notification settings - Fork 50
/
user.py
executable file
·43 lines (39 loc) · 1.1 KB
/
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
from PyInquirer import prompt
from csv import reader, writer
user_questions = [
{
"type": "input",
"name": "name",
"message": "New User - Name: ",
}
]
def getUsersList():
with open("users.csv", "r") as csv:
users = reader(csv)
res = []
for user in users:
res.append({'name': user[0]})
return res
def add_user():
userFileNameW = open("users.csv", "a")
userFileNameR = open("users.csv", "r")
usersReader = reader(userFileNameR)
usersWriter = writer(userFileNameW)
name = prompt(user_questions)["name"]
# See if user already exists
for user in usersReader:
if user[0].lower() == name.lower():
print("User " + name + " already exists !")
userFileNameR.close()
userFileNameW.close()
return False
# Spaces not allowed
if ' ' in name:
print("Spaces are not allowed !")
return add_user()
# Add User
usersWriter.writerow([name])
print("User " + name + " added !")
userFileNameR.close()
userFileNameW.close()
return True