resolve alias collisions
This commit is contained in:
parent
d91e90b145
commit
dabc89f588
1 changed files with 17 additions and 9 deletions
|
@ -145,14 +145,22 @@ def maybe_generate_aliases(
|
||||||
if reuse_aliases:
|
if reuse_aliases:
|
||||||
print("Reusing generated aliases")
|
print("Reusing generated aliases")
|
||||||
return False
|
return False
|
||||||
else:
|
|
||||||
|
alias_to_email_address = {}
|
||||||
|
|
||||||
for row in csv_contents:
|
for row in csv_contents:
|
||||||
random = Random(
|
rnd = Random("; ".join([row[KnownColumns.EmailAddress], args.csv, args.files]))
|
||||||
"; ".join([row[KnownColumns.EmailAddress], args.csv, args.files])
|
random_alias = f"{rnd.choice(alias_parts[0])} {rnd.choice(alias_parts[0])}"
|
||||||
)
|
while (
|
||||||
row[KnownColumns.GeneratedAlias] = (
|
random_alias in alias_to_email_address
|
||||||
f"{random.choice(alias_parts[0])} {random.choice(alias_parts[0])}"
|
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")
|
print("Generated an alias for each entry")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue