Skip to content

Commit 580548a

Browse files
committed
[Added] Initial Commit
0 parents  commit 580548a

File tree

5 files changed

+145
-0
lines changed

5 files changed

+145
-0
lines changed

Diff for: contact.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Contact:
2+
def __init__(self, name, email=None, phone=None):
3+
self.name = name
4+
self.email = email
5+
self.phone = phone
6+
7+
def __repr__(self):
8+
return f"Contact(name={self.name}, email={self.email}, phone={self.phone})"
9+
10+
def update(self, registrant):
11+
# Update contact with registrant details if missing
12+
if not self.name and registrant['name']:
13+
self.name = registrant['name']
14+
if not self.email and registrant['email']:
15+
self.email = registrant['email']
16+
if not self.phone and registrant['phone']:
17+
self.phone = registrant['phone']
18+
19+
20+
21+
22+
23+

Diff for: lead.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Lead:
2+
def __init__(self, name=None, email=None, phone=None):
3+
self.name = name
4+
self.email = email
5+
self.phone = phone
6+
7+
def __repr__(self):
8+
return f"Lead(name={self.name}, email={self.email}, phone={self.phone})"
9+
10+
def update(self, registrant):
11+
# Update contact with registrant details if missing
12+
if not self.name and registrant['name']:
13+
self.name = registrant['name']
14+
if not self.email and registrant['email']:
15+
self.email = registrant['email']
16+
if not self.phone and registrant['phone']:
17+
self.phone = registrant['phone']

Diff for: main.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from contact import Contact
2+
from lead import Lead
3+
from utils import match_and_add_contact
4+
from register import register_user
5+
6+
# Initial/Demo contacts data
7+
contacts = [
8+
Contact("Alice Brown", None, "1231112223"),
9+
Contact("Bob Crown", "[email protected]", None),
10+
Contact("Carlos Drew", "[email protected]", "3453334445"),
11+
Contact("Doug Emerty", None, "4564445556"),
12+
Contact("Egan Fair", "[email protected]", "5675556667")
13+
]
14+
15+
# Initial/Demo leads data
16+
leads = [
17+
Lead(None, "[email protected]", None),
18+
Lead("Lucy", "[email protected]", "3210001112"),
19+
Lead("Mary Middle", "[email protected]", "3331112223"),
20+
Lead(None, None, "4442223334"),
21+
Lead(None, "[email protected]", None)
22+
]
23+
24+
def process_registration(contacts, leads):
25+
# Allow the user to register and then process the registration
26+
while True:
27+
print("\nRegister for the Webinar!")
28+
registrant = register_user()
29+
if registrant == {}:
30+
continue
31+
contacts, leads = match_and_add_contact(contacts, leads, registrant)
32+
33+
# Ask if the user wants to register more people
34+
another = input("\nDo you want to register another user? (yes/no): ").strip().lower()
35+
if another != "yes":
36+
break
37+
38+
# Output the final contacts list
39+
print("\nFinal Contacts List:")
40+
for contact in contacts:
41+
print(contact)
42+
43+
# Start the registration process
44+
process_registration(contacts, leads)
45+

Diff for: register.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
def validate_phone_number(phone_number):
2+
if phone_number is None:
3+
return True
4+
5+
# Check if the phone number contains only digits and has exactly 10 characters
6+
return phone_number.isdigit() and len(phone_number) == 10
7+
8+
9+
def register_user():
10+
# Taking input from the user (simulating registration)
11+
name = input("Enter your name: ").strip()
12+
email = input("Do you have an email? (yes/no): ").strip().lower()
13+
email = input("Enter your email: ").strip() if email == "yes" else None
14+
phone = input("Do you have a phone number? (yes/no): ").strip().lower()
15+
phone = input("Enter your phone number: ").strip() if phone == "yes" else None
16+
17+
if not validate_phone_number(phone):
18+
print("Phone number is invalid. It must be exactly 10 digits and contain no other characters.")
19+
return {}
20+
21+
if phone == None and email == None:
22+
print("Phone and Email both can not be empty!")
23+
return {}
24+
else:
25+
return {"name": name, "email": email, "phone": phone}

Diff for: utils.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from contact import Contact
2+
3+
def match_and_add_contact(contacts, leads, registrant):
4+
# Try to match registrant's email to our list of contacts
5+
for contact in contacts:
6+
if contact.email == registrant['email'] and contact.email != None:
7+
contact.update(registrant)
8+
return contacts, leads
9+
10+
# Try to match registrant's phone to our contacts
11+
for contact in contacts:
12+
if contact.phone == registrant['phone'] and contact.phone != None:
13+
contact.update(registrant)
14+
return contacts, leads
15+
16+
# Try to match leads with email
17+
for lead in leads:
18+
if lead.email == registrant['email'] and lead.email != None:
19+
lead.update(registrant)
20+
contacts.append(Contact(lead.name, lead.email, lead.phone))
21+
leads.remove(lead)
22+
return contacts, leads
23+
24+
# Try to match leads with phone
25+
for lead in leads:
26+
if lead.phone == registrant['phone'] and lead.phone != None:
27+
lead.update(registrant)
28+
contacts.append(Contact(lead.name, lead.email, lead.phone))
29+
leads.remove(lead)
30+
return contacts, leads
31+
32+
33+
# If no match is found, add to contacts
34+
contacts.append(Contact(registrant['name'], registrant['email'], registrant['phone']))
35+
return contacts, leads

0 commit comments

Comments
 (0)