forked from katua123/Group-2-Work
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
29 lines (24 loc) · 895 Bytes
/
functions.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
import re
# Function to remove special characters from names
def sanitize_name(name):
# Remove non-alphanumeric characters (except spaces)
return re.sub(r'[^A-Za-z0-9 ]+', '', name)
# Function to generate email address
def generate_email(name, existing_emails):
# Sanitize the name by removing special characters
name = sanitize_name(name)
parts = name.split()
# Generate email based on the available names
if len(parts) == 1:
email_prefix = parts[0].lower()
elif len(parts) >= 2:
email_prefix = parts[0][0].lower() + parts[-1].lower()
# Ensure uniqueness of the email address
email = f"{email_prefix}@gmail.com"
counter = 1
while email in existing_emails:
email = f"{email_prefix}{counter}@gmail.com"
counter += 1
# Add the email to the existing emails set
existing_emails.add(email)
return email