1
0
Fork 0

* Added firstname.lastname case

* Allowed hyphens in names
* Converted all fullnames to usernames
This commit is contained in:
jochan 2017-11-10 09:32:43 -08:00
parent 578f86e720
commit e1e58926b8
2 changed files with 27 additions and 15 deletions

View File

@ -5,15 +5,16 @@ import os
failed_pattern = re.compile("^\*\*\*.*$") failed_pattern = re.compile("^\*\*\*.*$")
null_author = re.compile("^<>$") null_author = re.compile("^<>$")
visier_prepended = re.compile("^VISIER\\\.*$") visier_prepended = re.compile("^VISIER\\\.*$")
full_name_no_email = re.compile("^([A-Z]\w*\s?)+$") full_name_no_email = re.compile("^([A-Z][\w\-]*\s?)+$")
full_name_null_email = re.compile("^([A-Z]\w*\s?)+<>$") full_name_null_email = re.compile("^([A-Z][\w\-]*\s?)+<>$")
full_name_with_email = re.compile("^([A-Z]\w*\s?)+<.+>$") full_name_with_email = re.compile("^([A-Z][\w\-]*\s?)+<.+>$")
username_no_email = re.compile("^\w*$") username_no_email = re.compile("^[\w\-]*$")
username_null_email = re.compile("^\w*\s?<>$") username_null_email = re.compile("^[\w\-]*\s?<>$")
username_with_email = re.compile("^\w*\s?<.+>$") username_with_email = re.compile("^[\w\-]*\s?<.+>$")
username_sqr_email = re.compile("^\w*\s?\[.*\]$") username_sqr_email = re.compile("^[\w\-]*\s?\[.*\]$")
username_rnd_name = re.compile("^\w*\s?\(.*\)$") username_rnd_name = re.compile("^[\w\-]*\s?\(.*\)$")
username_address = re.compile("^\w*@.*$") username_address = re.compile("^[\w\-]*@.*$")
first_last_name = re.compile("^[\w\-]*\.[\w\-]*$")
any_any = re.compile("^.+<.*>$") any_any = re.compile("^.+<.*>$")
null_any = re.compile("^<.*>$") null_any = re.compile("^<.*>$")
any_email = re.compile("^.+\s\S+@\S+$") any_email = re.compile("^.+\s\S+@\S+$")
@ -32,6 +33,12 @@ def email_from_username(author):
def username_from_email(author): def username_from_email(author):
return next((user["username"] for user in users if user["email"] == author), "") return next((user["username"] for user in users if user["email"] == author), "")
def username_from_fullname(author):
return next((user["username"] for user in users if user["name"] == author), "")
def username_from_firstname_lastname(author):
return next((user["username"] for user in users if user["name"].casefold() == author.replace(".", " ").casefold()), "")
def replace_author(author): def replace_author(author):
if failed_pattern.match(author): if failed_pattern.match(author):
return "nulluser <>" return "nulluser <>"
@ -40,12 +47,13 @@ def replace_author(author):
if visier_prepended.match(author): if visier_prepended.match(author):
return replace_author(author[7:]) return replace_author(author[7:])
if full_name_with_email.match(author): if full_name_with_email.match(author):
return author fullname = author.split("<")[0].strip()
return username_from_fullname(fullname) + " <{}>".format(email_from_fullname(fullname))
if full_name_null_email.match(author): if full_name_null_email.match(author):
fullname = author.strip()[:-2].strip() fullname = author.strip()[:-2].strip()
return fullname + " <{}>".format(email_from_fullname(fullname)) return username_from_fullname(fullname) + " <{}>".format(email_from_fullname(fullname))
if full_name_no_email.match(author): if full_name_no_email.match(author):
return author.strip() + " <{}>".format(email_from_fullname(author.strip())) return username_from_fullname(author.strip()) + " <{}>".format(email_from_fullname(author.strip()))
if username_with_email.match(author): if username_with_email.match(author):
return author return author
if username_null_email.match(author): if username_null_email.match(author):
@ -61,6 +69,9 @@ def replace_author(author):
if username_address.match(author): if username_address.match(author):
username = author.split("@")[0] username = author.split("@")[0]
return username + " <{}>".format(email_from_username(username)) return username + " <{}>".format(email_from_username(username))
if first_last_name.match(author):
username = username_from_firstname_lastname(author)
return username + " <{}>".format(email_from_username(username))
if any_any.match(author): if any_any.match(author):
return author return author
if null_any.match(author): if null_any.match(author):

View File

@ -2,9 +2,9 @@ format matches replace
------ ------- ------- ------ ------- -------
*** failed to import... ^\*\*\*.*$ "nulluser <>" *** failed to import... ^\*\*\*.*$ "nulluser <>"
<> ^<>$ prepend with "nulluser " <> ^<>$ prepend with "nulluser "
Full Name ^([A-Z]\w*\s?)+$ append with <email> Full Name ^([A-Z]\w*\s?)+$ fullname with username and append with <email>
Full Name <> ^([A-Z]\w*\s?)+<>$ <> with <email> Full Name <> ^([A-Z]\w*\s?)+<>$ fullname with username and <> with <email>
Full Name <name@email.com> ^([A-Z]\w*\s?)+<.*>$ do nothing Full Name <name@email.com> ^([A-Z]\w*\s?)+<.*>$ fullname with username
VISIER\username <name@email.com> ^VISIER\\.*$ drop 7 and recurse VISIER\username <name@email.com> ^VISIER\\.*$ drop 7 and recurse
username ^\w*$ append with <email> username ^\w*$ append with <email>
username <> ^\w*\s?<>$ <> with <email> username <> ^\w*\s?<>$ <> with <email>
@ -12,6 +12,7 @@ username <name@email.com> ^\w*\s?<.*>$ do nothing
username [name@email.com] ^\w*\s?\[.*\]$ [ with < and ] with > username [name@email.com] ^\w*\s?\[.*\]$ [ with < and ] with >
username (Full Name) ^\w*\s?\(.*\)$ \s?\(.*\) with \s<email> username (Full Name) ^\w*\s?\(.*\)$ \s?\(.*\) with \s<email>
username@address.com ^\w*@.*$ @.* with \s<email> username@address.com ^\w*@.*$ @.* with \s<email>
firstname.lastname ^\w*\.\w*$ username <email> from fullname from firstname.lastname
anything <anything> ^.+<.*>$ do nothing anything <anything> ^.+<.*>$ do nothing
<anything> ^<.*>$ prepend with user <anything> ^<.*>$ prepend with user
anything name@email.com ^.+\s\S+@\S+$ wrap email with <> anything name@email.com ^.+\s\S+@\S+$ wrap email with <>