Created
October 8, 2014 03:59
-
-
Save lovesh/4a0f76e3d52e7b3cdc16 to your computer and use it in GitHub Desktop.
Email generator according to the spreadsheet http://bit.ly/name2email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
name = 'FirstName MiddleName LastName' | |
company_domain = 'company.com' | |
name_parts = name.lower().split(' ') | |
fname, mname, lname = None, None, None | |
if len(name_parts) > 0: | |
fname = name_parts[0] | |
if len(name_parts) > 1: | |
lname = name_parts[1] | |
if len(name_parts) > 2: | |
mname = name_parts[1] | |
lname = name_parts[2] | |
if len(name_parts) > 3: | |
mname = None # not sure what the middle name could be so None | |
lname = name_parts[-1] | |
possible_emails = [] | |
separators = ['.', '-', '_', ''] | |
if fname and not lname and not mname: | |
possible_emails = ['%s@%s'%(fname, fname[0]), '%s@%s'%(fname[0], fname)] | |
if fname and lname and not mname: | |
fi = fname[0] | |
li = lname[0] | |
permutations = list(itertools.product((fi, fname), (li, lname))) + list(itertools.product((li, lname), (fi, fname))) | |
for pm in permutations: | |
possible_emails.extend(['%s%s%s@%s'%(pm[0], sep, pm[1], company_domain) for sep in separators]) | |
if fname and lname and mname: | |
fi = fname[0] | |
li = lname[0] | |
mi = mname[0] | |
fl_permutations = list(itertools.product((fi, fname), (li, lname))) + list(itertools.product((li, lname), (fi, fname))) | |
permutations = [] | |
map(lambda fl: permutations.extend([fl, (fl[0], mname, fl[1]), (fl[0], mi, fl[1])]), fl_permutations) | |
for pm in permutations: | |
if len(pm) == 2: | |
possible_emails.extend(['%s%s%s@%s'%(pm[0], sep, pm[1], company_domain) for sep in separators]) | |
if len(pm) == 3: | |
possible_emails.extend(['%s%s%s%s%s@%s'%(pm[0], sep, pm[1], sep, pm[2], company_domain) for sep in separators]) | |
print possible_emails |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment