feat: multiple words

This commit is contained in:
2026-06-15 14:22:40 +02:00
parent b387fec2b3
commit d5b9018ef2
4 changed files with 19 additions and 6 deletions
+7 -3
View File
@@ -14,12 +14,13 @@ class FactoryError(Exception):
class Factory:
__slots__ = ["__found", "__tld_list", "__word_list", "logger", "logger"]
__slots__ = ["__found", "__tld_list", "__word_list", "logger", "__words"]
def __init__(self, tld_list: TLDList, word_list: WordList) -> None:
def __init__(self, tld_list: TLDList, word_list: WordList, words: int) -> None:
self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)
self.__tld_list = tld_list
self.__word_list = word_list
self.__words = words
self.__found: set[str] = set()
def __iter__(self) -> typing.Self:
@@ -65,7 +66,7 @@ class Factory:
return domain
def __random_domain(self) -> str | None:
word = random.choice(self.__word_list.words) # noqa: S311
word = self.__random_word()
for tld in self.__tld_list_shuffled:
tld_escaped = tld.replace(".", "")
if word.endswith(tld_escaped) and len(word) > len(tld_escaped):
@@ -74,3 +75,6 @@ class Factory:
self.__found.add(domain)
return domain
return None
def __random_word(self) -> str:
return "-".join(random.sample(self.__word_list.words, self.__words))