Skip to content

Instantly share code, notes, and snippets.

@safebuffer
Created October 9, 2020 17:41
Show Gist options
  • Save safebuffer/676b704c2f56c69f3ea010c86cae48a3 to your computer and use it in GitHub Desktop.
Save safebuffer/676b704c2f56c69f3ea010c86cae48a3 to your computer and use it in GitHub Desktop.
Names to Usernames
#!/usr/bin/env python
import itertools
import sys
def GenerateUsername(name):
USERNAMES = []
try:
import unidecode
name = unidecode.unidecode(name)
except Exception as e:
pass
def GetLists(names=[]):
ret = []
lists = []
if len(names) > 2:
lists+= list(itertools.permutations(names, 3))
lists+= list(itertools.permutations(names, 2))
for s in lists:
ret.append('.'.join(s))
ret.append('_'.join(s))
return ret
name = str(name).lower()
fullname = str(name).lower()
first_name,mid_name,last_name = None,None,None
names = name.split()
len_name = len(names)
if len_name == 2:
first_name = names[0]
last_name = names[1]
USERNAMES+= list(GetLists([first_name,last_name]))
elif len_name == 3:
first_name = names[0]
mid_name = names[1].replace('.','')
mid_name = mid_name.replace('`','')
last_name = names[2]
USERNAMES+= list(GetLists([first_name,last_name,mid_name]))
elif len_name == 4:
# well idk what to do with ppl who write CISSP|OSCP|OFUCK next to their names !
pass
if fullname:
USERNAMES.append(fullname.replace(' ','.'))
USERNAMES.append(fullname.replace(' ',''))
if all([first_name,last_name]):
USERNAMES.append(first_name)
USERNAMES.append(last_name)
USERNAMES.append(f"{first_name[0]}.{last_name}")
USERNAMES.append(f"{last_name[0]}.{first_name}")
USERNAMES.append(f"{first_name}.{last_name[0]}")
USERNAMES.append(f"{last_name}.{first_name[0]}")
if all([first_name,last_name,mid_name]):
USERNAMES.append(f"{first_name[0]}.{mid_name}")
USERNAMES.append(f"{mid_name[0]}.{first_name}")
USERNAMES.append(f"{last_name[0]}.{mid_name}")
USERNAMES.append(f"{mid_name[0]}.{last_name}")
return USERNAMES
OUTPUT = []
names = open(sys.argv[1],'r').readlines()
for name in names:
name = name.replace('\n','')
OUTPUT += GenerateUsername(name)
for username in OUTPUT:
print(username)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment