-
-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding permutator feature for usernames (#1575)
* Adding permutator feature for usernames ("", "_", "-", ".") when id_type == username File : maigret/permutator.py Arg : --permute For now, only permute from 2 elements and doesn't return single elements (element1, _element1, element1_, element2, _element2, ...). 12 permuts for 2 elements. To return single elements as well, Permute(usernames).gather(method="all"), but not implemented in maigrat.py. 18 permuts for 2 elements. Should we ? With another argument ? * Update test_cli.py permute arg added
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# License MIT. by balestek https://github.com/balestek | ||
from itertools import permutations | ||
|
||
|
||
class Permute: | ||
def __init__(self, elements: dict): | ||
self.separators = ["", "_", "-", "."] | ||
self.elements = elements | ||
|
||
def gather(self, method: str = "strict" or "all") -> dict: | ||
permutations_dict = {} | ||
for i in range(1, len(self.elements) + 1): | ||
for subset in permutations(self.elements, i): | ||
if i == 1: | ||
if method == "all": | ||
permutations_dict[subset[0]] = self.elements[subset[0]] | ||
permutations_dict["_" + subset[0]] = self.elements[subset[0]] | ||
permutations_dict[subset[0] + "_"] = self.elements[subset[0]] | ||
else: | ||
for separator in self.separators: | ||
perm = separator.join(subset) | ||
permutations_dict[perm] = self.elements[subset[0]] | ||
if separator == "": | ||
permutations_dict["_" + perm] = self.elements[subset[0]] | ||
permutations_dict[perm + "_"] = self.elements[subset[0]] | ||
return permutations_dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters