-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyphonebook.py
684 lines (616 loc) · 32.3 KB
/
myphonebook.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
### a simple phone book project with python3 ###
# IMPORT REGEX
import re
# IMPORT COLORS
from colorama import Fore, Back, Style
# IMPORT TIME MODULE
import time
#IMPORT ARGUMENT PARSER
import argparse
#IMPORT SYS
import sys
# CLEAR SCREAN
from clear_screen import clear
# FUCNTION TO BACK TO MENU
def back(back):
if back == "q!":
programe()
else:
pass
# MAX LENGTH CHECK
def check(item,n):
if len(item) <=n:
global max_char
max_char = False
else:
print(Fore.RED+"\nMax length is %i! try again.\n"%n,Style.RESET_ALL)
# OPEN PHONE BOOK DATA
try :
file = open("phone_book_data","r")
reader = file.read()
# READ DICTIONARY FROM FILE
import ast
phone_book = ast.literal_eval(reader)
file.close()
# IF THERE WAS NO DATABASE, CREATE ONE
except FileNotFoundError :
phone_book = {}
# A BOOLEAN TO CHECK IF CHANGES SAVED OR NOT
global SAVE
SAVE = True
# A FUNCTION TO CHECK THAT INPUT IS NOT EMPTY
def ask_user(message=''):
user_input = ''
while not user_input:
user_input = input(message)
return user_input
# MAIN FUNCTION OF PROGRAME
def programe():
# MENU
print("""
~MENU~
1) READ ALL CONTACTS
2) ADD A CONTACT
3) DELETE A CONTACT
4) SEARCH A CONTACT
5) EDIT A CONTACT
6) SAVE CHANGES
7) Exit\n""")
choose = ask_user(" Please select an Option: ")
# THIS FUNCTION SHOWS PERSONS INFORMATION IN A TABLE
def show(person):
print(Fore.BLUE+"\n>> %s"%person,Style.RESET_ALL,"'s informations: \n",sep="")
# DECRATE BEFORE PRINTING CONTACTS
print(" ","+","="*4,"+","="*15,"+","="*15,"+","="*30,"+","="*40,"+",sep="")
print(" ","|",Fore.RED+"ID".center(4),Style.RESET_ALL,"|",Fore.RED+"CONTACT NAME".center(15),Style.RESET_ALL,"|",Fore.RED+"PHONE NUMBER".center(15),Style.RESET_ALL,"|",Fore.RED+"E-MAIL".center(30),Style.RESET_ALL,"|",Fore.RED+"ADDRESS".center(40),Style.RESET_ALL,"|",sep="")
print(" ","+","="*4,"+","="*15,"+","="*15,"+","="*30,"+","="*40,"+",sep="")
for contact in phone_book[person]:
for info in contact :
print(" ","|",Fore.GREEN+contact[info]["ID"].center(4),Style.RESET_ALL,"|",info.center(15),"|",contact[info]["phone"].center(15),"|",contact[info]["email"].center(30),"|",contact[info]["address"].center(40),"|",sep="")
print(" ","+","-"*4,"+","-"*15,"+","-"*15,"+","-"*30,"+","-"*40,"+",sep="")
# PRINT PHONE BOOK
if choose == "1" :
clear()
def all_contacts():
# SORT BEFORE SHOW CONTACTS
sorted_contacts = sorted(phone_book)
for person in sorted_contacts :
show(person)
all_contacts()
programe()
# ADD NEW CONTACT
elif choose == "2" :
clear()
# MAKE AN ID FOR EACH CONTACT NAME
global contact_id
contact_id = 0
def add_a_name():
name = ask_user("Please enter a name (q! to menu) : ")
back(name)
# MAKE FIST LETTER UPPER CASE
name = name.capitalize()
# CHECK VALID NAME
if re.match("^[a-zA-Z ]+$", name):
contact_list = []
# CHECK NEW CONTACT EXIST IN PHONE BOOK OR NOT
if name in phone_book :
print(Fore.RED+"\n%s exist in phone book!\n"%name,Style.RESET_ALL)
add_a_name()
else :
print(Fore.RED+"\nWrong input! you can use \"english alphabet\" and \"white space\" for your name! try again.\n",Style.RESET_ALL)
add_a_name()
# ADD A CONTACT NAME LIKE : HOME, WORK, ...
def add_a_contact_name():
global SAVE, max_char
SAVE = False
# INPUT CONTACT NAME AND CHECK FOR MAXIMUM CHARACTER FOR CONTACT NAME
max_char = True
while max_char :
contact_name = ask_user("Please enter a contact name like (home/work,..) for %s: "%name)
check(contact_name,15)
global contact_id
contact_id += 1
contact_dict = {}
# INPUT PHONE NUMBER AND CHECK FOR VALIDATION AND MAX LIMIT
max_char = True
while max_char :
try :
phone = int(ask_user("Please enter phone number for %s's %s: "%(name,contact_name)))
phone = str(phone)
check(phone,15)
except :
print(Fore.RED+"\nThis is not a phone number! try again\n",Style.RESET_ALL)
# INPUT EMAIL AND CHECK FOR VALIDATION AND MAX LIMIT
max_char = True
while max_char :
mail = ask_user("Please enter email for %s's %s: "%(name,contact_name))
# CHECK VALID EMAIL
if re.match("(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", mail):
check(mail,30)
else :
print(Fore.RED+"\nThis is not an email! try again.\n",Style.RESET_ALL)
# INPUT ADDRESS AND CHECK FOR MAXIMUM CHARACTER
max_char = True
while max_char :
addr = ask_user("Please enter address for %s's %s: "%(name,contact_name))
check(addr,40)
# ADD THIS INPUTS TO PHONE BOOK
contact_dict[contact_name]={"ID":str(contact_id),"phone":phone,"email":mail,"address":addr}
contact_list.append(contact_dict)
# ASKS TO ADD ANOTHER CONTACT NAME OR NOT
def add_contact():
answer = ask_user("Do you want to add a new contact name for %s?(y/n): "%name)
if answer.upper() == "Y":
add_a_contact_name()
elif answer.upper() == "N":
phone_book[name]=contact_list
# ADDING NEW CONTACT FINISHED
print(Fore.GREEN+"\n\"%s\" succesfully added to your phone book!"%name,Style.RESET_ALL)
programe()
else :
print(Fore.RED+"\nWrong answer! try again.\n",Style.RESET_ALL)
add_contact()
add_contact()
add_a_contact_name()
add_a_name()
# DELETING A CONTACT
elif choose == "3" :
clear()
def delete():
name = ask_user("Enter the name of contact, you want to remove (q! to menu): ")
back(name)
name = name.capitalize()
if name in phone_book :
del phone_book[name]
print(Fore.GREEN+"\n\"%s\" has been successfully removed! "%name,Style.RESET_ALL)
global SAVE
SAVE = False
else:
print(Fore.RED+"\"%s\" not found!"%name,Style.RESET_ALL)
delete()
delete()
programe()
# SEARCH
elif choose == "4" :
clear()
def search():
search_by = ask_user("""
You can search by \"name\", \"number\" and \"email\" (q! to Menu) :
1) by name
2) by number
3) by email
:? """)
back(search_by)
# BY NAME
if search_by == "1" :
name = ask_user("\nPlease enter the name : ")
name = name.capitalize()
if name in phone_book :
show(name)
search()
else :
print(Fore.RED+"\n\"%s\" not found!"%name,Style.RESET_ALL)
search()
# BY NUMBER
elif search_by == "2" :
S = False
empty = []
number = ask_user('\nPlease enter the number: ')
for person in phone_book :
for contact in phone_book[person] :
if person not in empty :
for info in contact :
if contact[info]["phone"] == number :
empty.append(person)
show(person)
S = True
search()
if not S :
print(Fore.RED+"\n\"%s\" not found!"%number,Style.RESET_ALL)
search()
# BY EMAIL
elif search_by == "3" :
S = False
empty = []
email = ask_user('\nPlease enter the email address: ')
for person in phone_book :
for contact in phone_book[person] :
if person not in empty :
for info in contact :
if contact[info]["email"] == email :
empty.append(person)
show(person)
S = True
search()
if not S :
print(Fore.RED+"\n\"%s\" not found!"%email,Style.RESET_ALL)
search()
else :
print(Fore.RED+"\nWrong answer! try again.",Style.RESET_ALL)
search()
search()
programe()
# EDIT CONTACT
elif choose == "5":
clear()
# THIS TRY STATEMENT CREATED BECAUSE IF NAME HAS CHANGED BY USER, USER DOES NOT HAVE TO ENTER NEW NAME AGAIN TO RUN EDIT OPTION
def edit():
try :
person = new_name
except :
person = ask_user("\nEnter the name of contact you want to edit (q! to menu): ")
back(person)
person = person.capitalize()
if person in phone_book :
def edit_info(person):
item = ask_user("""\nWhat do you want to do?
1) show contact info
2) edit name
3) remove a row
4) add a row
5) edit a row
6) exit
:? """)
#SHOW INFO OF CONTACT
if item == "1" :
clear()
show(person)
edit_info(person)
# CHANGE THE NAME
elif item == "2" :
def change_name():
global new_name
new_name = ask_user("\nPlease enter a new name (enter c! for cancel): ")
# C! FOR CANCELING THIS OPRATION
if new_name == "c!" :
edit_info(person)
else:
new_name = new_name.capitalize()
# CHECK IF NEW NAME EXIST IN PHONE BOOK OR NOT
if new_name in phone_book :
print(Fore.RED+"\n\"%s\" Exist in phone book! choose another name."%new_name,Style.RESET_ALL)
change_name()
else:
pass
# CHECK FOR VALID NAME
if re.match("^[a-zA-Z ]+$", new_name):
phone_book[new_name] = phone_book.pop(person)
print(Fore.GREEN+"\nName changed to \"%s\" !"%new_name,Style.RESET_ALL)
global SAVE
SAVE = False
# AFTER THE NAME WAS CHANGE , EDIT FUNCTION HAS TO START AGAIN
edit()
else :
print(Fore.RED+"\nWrong input! you can use \"english alphabet\" and \"white space\" for your name! try again.",Style.RESET_ALL)
change_name()
change_name()
# DELETE A ROW
elif item == "3" :
S = False
id_to_del = str(ask_user("\nEnter ID to delete that row (enter c! for cancel): "))
if id_to_del == "c!" :
edit_info(person)
for contact in phone_book[person]:
for info in contact :
if id_to_del in list(contact[info]["ID"]) :
S = True
phone_book[person].remove(contact)
print(Fore.GREEN+"\nRow \"%s\" removed!"%id_to_del,Style.RESET_ALL)
global SAVE
SAVE = False
break
if not S :
print(Fore.RED+"\nRow \"%s\" not found!"%id_to_del,Style.RESET_ALL)
edit_info(person)
# ADD A ROW
elif item == "4" :
global max_char
# READ CONTACT ID ; IF THERE WAS NO ROW , ID WOULD BE 1
try :
for contact in phone_book[person]:
for info in contact :
contact_id = int(contact[info]["ID"])
contact_id = str(contact_id + 1)
except :
contact_id = 1
# ADD NEW CONTACT NAME
max_char = True
while max_char :
new_contact_name = ask_user("\nPlease enter new contact name to add (enter c! for cancel): ")
if new_contact_name == "c!" :
edit_info(person)
check(new_contact_name,15)
contact_dict = {}
# ADD NEW PHONE NUMBER
max_char = True
while max_char :
# CHECK FOR VAKID PHONE NUMBER
try :
phone = int(ask_user("Please enter phone number: "))
phone = str(phone)
check(phone,15)
except :
print(Fore.RED+"\nThis is not a phone number! try again\n",Style.RESET_ALL)
# ADD NEW EMAIL
max_char = True
while max_char :
mail = ask_user("Please enter email: ")
# CHECK VALID EMAIL
if re.match("(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", mail):
check(mail,30)
else :
print(Fore.RED+"\nThis is not an email! try again.\n",Style.RESET_ALL)
# ADD NEW ADDRESS
max_char = True
while max_char :
addr = ask_user("Please enter address: ")
check(addr,40)
# ADD INFORMATIONS TO PHONE BOOK
contact_dict[new_contact_name]={"ID":str(contact_id),"phone":phone,"email":mail,"address":addr}
phone_book[person].append(contact_dict)
print(Fore.GREEN+"\n\"%s\" successfully added!"%new_contact_name,Style.RESET_ALL)
SAVE = False
edit_info(person)
# EDIT A ROW
elif item == "5" :
def edit_row():
id_to_edit = ask_user("\nEnter ID to edit the row (c! for cancel): ")
S = False
for contact in phone_book[person]:
for info in contact :
if id_to_edit == contact[info]["ID"]:
S = True
clear()
def sub_edit():
global max_char
choose = ask_user("""\nwhat are you gonna do?
1) show row info
2) edit Contact Name
3) edit Phone number
4) edit E-mail
5) edit Address
6) exit
?: """) # SHOW TABLE
if choose == "1" :
clear()
print(Fore.BLUE+"\n>> %s"%person,Style.RESET_ALL,"'s informations: \n",sep="")
# DECRATE BEFORE PRINTING CONTACTS
print(" ","+","="*4,"+","="*15,"+","="*15,"+","="*30,"+","="*40,"+",sep="")
print(" ","|",Fore.RED+"ID".center(4),Style.RESET_ALL,"|",Fore.RED+"CONTACT NAME".center(15),Style.RESET_ALL,"|",Fore.RED+"PHONE NUMBER".center(15),Style.RESET_ALL,"|",Fore.RED+"E-MAIL".center(30),Style.RESET_ALL,"|",Fore.RED+"ADDRESS".center(40),Style.RESET_ALL,"|",sep="")
print(" ","+","="*4,"+","="*15,"+","="*15,"+","="*30,"+","="*40,"+",sep="")
for contact in phone_book[person]:
for info in contact :
# JUST PRINT A ROW THAT USER WANTS
if id_to_edit == contact[info]["ID"] :
print(" ","|",Fore.GREEN+contact[info]["ID"].center(4),Style.RESET_ALL,"|",info.center(15),"|",contact[info]["phone"].center(15),"|",contact[info]["email"].center(30),"|",contact[info]["address"].center(40),"|",sep="")
print(" ","+","-"*4,"+","-"*15,"+","-"*15,"+","-"*30,"+","-"*40,"+",sep="")
sub_edit()
# EDIT CONTACT NAME
elif choose == "2" :
max_char = True
while max_char :
new_contact_name = ask_user("\nEnter new contact name: ")
check(new_contact_name,15)
if not max_char :
global SAVE
SAVE = False
for contact in phone_book[person]:
for info in contact :
if id_to_edit == contact[info]["ID"]:
contact[new_contact_name] = contact.pop(info)
print(Fore.GREEN+"\ncontact name changed to \"%s\""%new_contact_name,Style.RESET_ALL)
sub_edit()
# EDIT PHONE NUMBER
elif choose == "3" :
max_char = True
while max_char :
# CHECK FOR VALID PHONE NUMBER
try :
new_phone_number = int(ask_user("\nEnter new phone number: "))
new_phone_number = str(new_phone_number)
check(new_phone_number,15)
except :
print(Fore.RED+"\nThis is not a phone number! try again",Style.RESET_ALL)
if not max_char :
for contact in phone_book[person]:
for info in contact :
if id_to_edit == contact[info]["ID"] :
contact[info]["phone"] = new_phone_number
print(Fore.GREEN+"\nphone number changed to \"%s\""%new_phone_number,Style.RESET_ALL)
SAVE = False
sub_edit()
# EDIT EMAIL
elif choose == "4" :
max_char = True
while max_char :
new_email = ask_user("\nEnter new email: ")
# CHECK VALID EMAIL
if re.match("(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", new_email):
check(new_email,30)
else :
print(Fore.RED+"\nThis is not an email! try again.",Style.RESET_ALL)
if not max_char :
for contact in phone_book[person]:
for info in contact :
if id_to_edit == contact[info]["ID"] :
contact[info]["email"] = new_email
print(Fore.GREEN+"\nemail changed to \"%s\""%new_email,Style.RESET_ALL)
SAVE = False
sub_edit()
# EDIT ADDRESS
elif choose == "5" :
max_char = True
while max_char :
new_addr = ask_user("\nEnter new address: ")
check(new_addr,40)
if not max_char :
for contact in phone_book[person]:
for info in contact :
if id_to_edit == contact[info]["ID"] :
contact[info]["address"] = new_addr
print(Fore.GREEN+"\nAddress changed to \"%s\""%new_addr,Style.RESET_ALL)
SAVE = False
sub_edit()
# EXIT AND BACK TO MENU
elif choose == "6" :
edit_info(person)
else :
print(Fore.RED+"\nWrong answer! try again.",Style.RESET_ALL)
sub_edit()
sub_edit()
elif id_to_edit == "c!" :
edit_info(person)
if not S :
print(Fore.RED+"\n\"%s\" not found! try again."%id_to_edit,Style.RESET_ALL)
edit_row()
edit_row()
# BACK TO MAIN MENU
elif item == "6" :
try :
# DELETE NEW NAME VARIABLE
global new_name
del new_name
except :
pass
programe()
else:
print(Fore.RED+"\nWrong answer! try again.",Style.RESET_ALL)
edit_info(person)
edit_info(person)
else :
print(Fore.RED+"\n%s not found! try again."%person,Style.RESET_ALL)
edit()
edit()
programe()
# SAVE CHANGES
elif choose =="6" :
def write () :
file = open("phone_book_data","w")
file.write(str(phone_book))
file.close()
print(Fore.GREEN+"\n Changes saved successfully!",Style.RESET_ALL)
global SAVE
SAVE = True
programe()
write()
# EXIT
elif choose == "7" :
def quit():
# EXIT, IF CHANGES HAVE BEEN SAVED
if SAVE == True :
print(" BYE!")
time.sleep(3)
clear()
exit()
elif SAVE == False :
# ASK TO EXIT OR NOT WHEN CHANGES HAVE NOT SAVED
print("\n The changes have not been saved yet! do you want to save before quit?",Fore.RED+"(y/n): ",Style.RESET_ALL,end="")
answer = input("")
# SAVE BEFORE EXIT
if answer.upper() == "Y" :
file = open("phone_book_data","w")
file.write(str(phone_book))
file.close()
print(Fore.GREEN+"\n Changes saved successfully!",Style.RESET_ALL)
print(" BYE!")
time.sleep(3)
clear()
exit()
# EXIT WITHOUT SAVE
elif answer.upper() == "N" :
print(" BYE!")
time.sleep(3)
clear()
exit()
else :
quit()
quit()
# WRONG ANSWER
else:
print(Fore.RED+"\n Wrong! please select again. \n",Style.RESET_ALL)
programe()
#Get options from the command line
def ArgumentParser():
#Define the options
parser = argparse.ArgumentParser(prog="myphonebook",description="--> a program for save and read your contacts information <--",
epilog="E.g : {%(prog)s Test -v} this command show all of information Related to Test")
parser.add_argument("name",help="Show contact information by name", nargs="*")
parser.add_argument("-v", "--verbosity", help="Show more information from contacts {Can not be used with [-A]}", action="store_true")
# Options that conflict each other
conflicts = parser.add_mutually_exclusive_group()
conflicts.add_argument("-A", help="Show all contact numbers", dest="ShowAll", action="store_true")
conflicts.add_argument("-n", "--number", help="Show contact information by number", dest="ContactNumber", type=int, required=False)
#a function for show complet information (for verbosity option)
def CompletInfo(ContactName,pattern,PatternType):
global phone_book
# show additional information by name:
if PatternType == 'name':
for info in phone_book[pattern]:
for contact in info:
if contact == ContactName:
print("{0} ID --> {1}".format(ContactName,info[ContactName]['ID']))
print("{0} Email --> {1}".format(ContactName,info[ContactName]['email']))
print("{0} Address --> {1}".format(ContactName,info[ContactName]['address']))
print(25*"-")
#show additional information by number:
elif PatternType == 'number':
for name in phone_book:
for info in phone_book[name]:
for contact in info:
if contact == ContactName:
if info[ContactName]['phone'] == pattern:
print("{0} ID --> {1}".format(ContactName, info[ContactName]['ID']))
print("{0} Email --> {1}".format(ContactName, info[ContactName]['email']))
print("{0} Address --> {1}".format(ContactName, info[ContactName]['address']))
print(25*"-")
# if the input option was name:
def PrintInformation():
if arguments.name:
name =' '.join(arguments.name)
name = name.capitalize()
if name in phone_book:
print(Fore.CYAN+"--> {} <--".format(name), Style.RESET_ALL)
for contacts in phone_book[name]:
for info in contacts:
print("{0} phone --> {1}".format(info, contacts[info]['phone']))
if arguments.verbosity:
CompletInfo(info, name, 'name')
else:
print(Fore.RED+" Name not found\n",Style.RESET_ALL)
# check if the input option was number (-n):
if arguments.ContactNumber:
CheckInNumber = False
InputNumber = str(arguments.ContactNumber)
for name in phone_book:
for info in phone_book[name]:
contacts = ''.join(info.keys())
#check number in data
if InputNumber == info[contacts]['phone']:
CheckInNumber = True
print(Fore.CYAN+"--> {} <--".format(name),Style.RESET_ALL)
print("{0} phone --> {1}".format(contacts, info[contacts]['phone']))
if arguments.verbosity:
CompletInfo(contacts, InputNumber, 'number')
if not CheckInNumber:
print(Fore.RED+" Number not found\n",Style.RESET_ALL)
# check if input options was [-A]
if arguments.ShowAll:
for name in phone_book:
for info in phone_book[name]:
contacts = ''.join(info.keys())
print(Fore.CYAN+"(%s)"%name, Style.RESET_ALL,"{1} number --> {2}".format(name, contacts, info[contacts]['phone']), Style.RESET_ALL)
#check invalid input options
try:
arguments = parser.parse_args()
PrintInformation()
except SystemExit:
print(Fore.RED+"use [-h] for show help message ",Style.RESET_ALL)
#check for option
if len(sys.argv) == 1:
# show message when breaking the program
try:
programe()
except (EOFError, KeyboardInterrupt) as Erorrs:
print(Fore.RED+"\n\n<<< Ohh! program was broken.please try again >>>\n",Style.RESET_ALL)
elif len(sys.argv) > 1:
ArgumentParser()