-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusername_generation.py
executable file
·55 lines (41 loc) · 1.9 KB
/
username_generation.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
#!/usr/bin/python3
import re
def generate_usernames(name, surname):
# Remove special characters using regex
name = re.sub(r"[^\w\s]", "", name)
surname = re.sub(r"[^\w\s]", "", surname)
# Create the base variations
variations = set()
# Capitalized versions
variations.add(name) # Original name
variations.add(name.lower()) # Lowercase name
variations.add(surname) # Original surname
variations.add(surname.lower()) # Lowercase surname
variations.add(surname.capitalize()) # Capitalized surname
# Combined versions
combined_name = name + surname # Combined original
combined_lower = combined_name.lower() # Combined lowercase
combined_capitalized = combined_name.capitalize() # Capitalized combined
variations.add(combined_name) # Original combined
variations.add(combined_lower) # Lowercase combined
variations.add(combined_capitalized) # Capitalized combined
return variations
def process_file(file_path):
all_usernames = set()
with open(file_path, 'r') as file:
for line in file:
# Split the line into name and surname
parts = line.strip().split()
if len(parts) < 2:
continue # Skip lines that don't have at least a name and surname
name = " ".join(parts[:-1]) # Join all but last part for name (to handle multi-part names)
surname = parts[-1] # Last part is the surname
usernames = generate_usernames(name, surname)
all_usernames.update(usernames)
return all_usernames
# Specify the path to your input file
input_file_path = 'names.txt' # Change this to your actual file path
usernames = process_file(input_file_path)
# Print the results sorted
for username in sorted(usernames):
print(username)