-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_friend.py
49 lines (45 loc) · 1.8 KB
/
add_friend.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
from spy_details import friend_list
from spy_details_class import Spy_Details
import re
from colorama import init, Fore
init()
nameexpr="^[a-zA-Z]+[\sa-zA-Z]*$";
ageexpr="^[0-9]+$"
ratingexpr="^[0-9]+\.[0-9]+$"
def add_friends():
sd = Spy_Details(); # new spy details object
sd.clear_chats(); # clears the chat list before adding new spy
error = "";
while True:
new_name = raw_input("Please enter your friends name:")
if re.match(nameexpr, new_name, flags=0) is not None:
break
else:
print(Fore.RED+"Name can only contain alphabets, name cannot be null and name cannot start with space. Please provide a valid name."+Fore.RESET);
if len(new_name)<=0 :
error=error+" "+"Name not entered";
new_salutation = raw_input("How do you want to address your friend")
while True:
new_age = raw_input("Please enter the age:")
if re.match(ageexpr, new_age, flags=0) is not None:
new_age=int(new_age);
break
else:
print(Fore.RED+"Age can only be a integer. Please re enter your age:"+Fore.RESET);
if new_age<=12 or new_age>=50:
error = error+" "+"Age not supported";
while True:
new_rating = raw_input("Enter your friends rating:");
if re.match(ratingexpr, new_rating, flags=0) is not None:
spy_rating = float(new_rating)
break
else:
print(Fore.RED + "Please provide a rating in decimal format. like 4.0 or 4.4 etc..!" + Fore.RESET);
if new_rating<2.5:
error = error+" "+"Rating not provided"
if(len(error)<=0):
print "Friend added to the list"
sd.set_details(new_name,new_salutation,new_age,new_rating,True)
friend_list.append(sd);
else:
print "Not added. Error occured: "+ error;