-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
119 lines (92 loc) · 2.84 KB
/
main.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import os.path
import FileOperations
from User import User
currentUser = User()
def addUser():
user = getUserData()
user.ID = FileOperations.getNextId()
FileOperations.addUser(user)
print("User has been added\n")
def searchByID():
id = int(input("Type user ID: "))
user = FileOperations.getUserById(id)
if user == None:
print("User wasn't found\n")
else:
print(user)
modifyUser(user)
def searchByName():
name = input("Type user name: ")
user = FileOperations.getUserByName(name)
if user == None:
print("User wasn't found\n")
else:
print(user)
modifyUser(user)
def searchByPhone():
phone = input("Type user phone: ")
user = FileOperations.getUserByPhone(phone)
if user == None:
print ("User wasn't found\n")
else:
print(user)
modifyUser(user)
def searchByEmail():
email = input("Type user E-mail: ")
user = FileOperations.getUserByEmail(email)
if user == None:
print ("User wasn't found\n")
else:
print(user)
modifyUser(user)
def printUsers():
users = FileOperations.getUsers(0, FileOperations.getNumberOfUsers())
print("{0:12}{1:32}{2:32}{3:32}".format('ID', 'Name', 'Phone', 'E-mail'))
for user in users:
print(user.getPrintableUser())
print("")
def getUserData():
user = User()
user.Name = input("Type user name: ")
user.Phone = input("Type user phone: ")
user.Email = input("Type user e-mail: ")
return user
def modifyUserData(user):
print("Type user data in each field (Type nothing in field you don't want to modify)")
name = input("Type user name: ")
if name.strip() != '':
user.Name = name
phone = input("Type user phone: ")
if phone.strip() != '':
user.Phone = phone
email = input("Type user e-mail: ")
if email.strip() != '':
user.Email = email
def modifyUser(user):
print("Type (M) to modify user data, (D) to delete user")
inp = input().lower().strip()
if inp == 'm':
modifyUserData(user)
FileOperations.modifyUserData(user)
print('User has been modified\n')
elif inp == 'd':
if input("Are you sure you want to delete user ?? (Y/N): ").lower().strip() == 'y':
FileOperations.deleteUser(user)
print("User has been deleted\n")
while 1:
print("(A) to Add new user, (D) to display users, (I) to search by ID, (N) to search by Name, (P) to search by Phone, (E) to search by E-mail, (Q) to exit")
choice = input().strip().lower()
if choice == 'a':
addUser()
elif choice == "i":
searchByID()
elif choice == 'n':
searchByName()
elif choice == 'p':
searchByPhone()
elif choice == 'e':
searchByEmail()
elif choice == "d":
printUsers()
else:
break