Open Noop3 opened 1 year ago
This definitely is not perfect but got the job done for me. Works for most names that have prefixes (von, El, di etc. ), assume it would work for middle names aswell. Might require some work for multiple middle names.
python3 ../crosslinked.py -f "{f}.{prefix}.{last}@google.de" "Google"
Replace in __init__.py
def nformatter(nformat, name):
# Get position of name values in text
tmp = nformat.split('}')
print(tmp)
f_position = int(re.search(r'(-?\d+)', tmp[0]).group(0)) if ':' in tmp[0] else 0
l_position = int(re.search(r'(-?\d+)', tmp[1]).group(0)) if ':' in tmp[1] else -1
# Extract names from raw text
tmp = name.split(' ')
# check if name contains prefix/middlename
if len(tmp) > 2:
f_name = tmp[0]
p_name = tmp[1:-1]
# combine prefixes with a period
p_name = '.'.join(map(str, p_name))
l_name = tmp[-1]
# Use replace function to create final output
val = re.sub(r'-?\d+:', '', nformat)
val = val.replace('{f}', f_name[0])
val = val.replace('{first}', f_name)
val = val.replace('{l}', l_name[0])
val = val.replace('{last}', l_name)
# if its a one char, or ends in period remove middle name
if p_name.endswith('.') or (len(p_name) == 1):
val = val.replace('.{prefix}', "")
val = val.replace('{prefix}', "")
else:
val = val.replace('{prefix}', p_name)
print(val)
return val
else:
try:
f_name = tmp[f_position] if len(tmp) > 2 else tmp[0]
l_name = tmp[l_position] if len(tmp) > 2 else tmp[-1]
except:
f_name = tmp[0]
l_name = tmp[-1]
# Use replace function to create final output
val = re.sub(r'-?\d+:', '', nformat)
val = val.replace('{f}', f_name[0])
val = val.replace('{first}', f_name)
val = val.replace('{l}', l_name[0])
val = val.replace('{last}', l_name)
# remove prefix name placeholder if it does not exist
val = val.replace('.{prefix}', "")
val = val.replace('{prefix}', "")
print(val)
return val
How do I search for not only first and last name, I want to combine middle name also