-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSMS manager.py
More file actions
90 lines (79 loc) · 2.64 KB
/
SMS manager.py
File metadata and controls
90 lines (79 loc) · 2.64 KB
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
import re
class Contact:
def __init__(self,name,phone,email):
self.name = name
self.phone = phone
self.email = email
self.message = ""
class Message:
def __init__(self,name):
self.name=name
self.baza=[]
def add_contact(self):
name=(input("enter your name:"))
while True:
phone = input("enter your phone:")
s = r'^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$'
if re.match(s, phone):
break
else:
print("raqamni noto'g'ri kiritingiz")
while True:
email = input("enter your email:")
a=r'[^@ \t\r\n]+@[^@ \t\r\n]+\.[^@ \t\r\n]+'
if re.match(a, email):
break
else:
print("emailni noto'g'ri kiritingiz")
p=Contact(name,phone,email)
self.baza.append(p)
def view_contact(self):
count=0
for item in self.baza:
count+=1
print(f'{count}. name:{item.name} phone:{item.phone} email:{item.email}')
def update_contact(self):
try:
self.view_contact()
index = int(input("Which one:"))
contact = self.baza[index - 1]
print("1.name\n2.phone\n3.email")
choice = input("Choice one:")
if choice == "1":
new_name = input("New name: ")
contact.name = new_name
elif choice == "2":
new_phone = input("New phone: ")
m = r'^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$'
if re.match(m, new_phone):
contact.phone = new_phone
elif choice == "3":
new_email = input("New email: ")
n = r'[^@ \t\r\n]+@[^@ \t\r\n]+\.[^@ \t\r\n]+'
if re.match(n, new_email):
contact.email = new_email
except ValueError:
print("Contact bo'sh")
def delete_contact(self):
self.view_contact()
index = int(input("Which one: "))
contact = self.baza[index - 1]
if index == 1:
del self.baza[index - 1]
print("<<<Deleted>>>")
a=Message("Contact")
def manager_contact(s:Message):
while True:
print("1.View contact\n2.Add contact\n3.Update\n4.delete contact\n5.Exit")
code=input("Enter code:")
if code=="1":
a.view_contact()
elif code=="2":
a.add_contact()
elif code=="3":
a.update_contact()
elif code=="4":
a.delete_contact()
else:
break
manager_contact(a)