resolve alias collisions

This commit is contained in:
Ash Garcia 2024-08-11 16:54:15 -07:00
parent d91e90b145
commit dabc89f588

View file

@ -145,14 +145,22 @@ def maybe_generate_aliases(
if reuse_aliases:
print("Reusing generated aliases")
return False
else:
alias_to_email_address = {}
for row in csv_contents:
random = Random(
"; ".join([row[KnownColumns.EmailAddress], args.csv, args.files])
)
row[KnownColumns.GeneratedAlias] = (
f"{random.choice(alias_parts[0])} {random.choice(alias_parts[0])}"
rnd = Random("; ".join([row[KnownColumns.EmailAddress], args.csv, args.files]))
random_alias = f"{rnd.choice(alias_parts[0])} {rnd.choice(alias_parts[0])}"
while (
random_alias in alias_to_email_address
and alias_to_email_address[random_alias] != row[KnownColumns.EmailAddress]
):
print(
f"WARNING: rerolling alias for {row[KnownColumns.EmailAddress]} due to collision with {alias_to_email_address[random_alias]}"
)
random_alias = f"{rnd.choice(alias_parts[0])} {rnd.choice(alias_parts[0])}"
row[KnownColumns.GeneratedAlias] = random_alias
print("Generated an alias for each entry")
return True