From d5b9018ef2adb236e5486d0a93e4f4270608f866 Mon Sep 17 00:00:00 2001 From: Klemek Date: Mon, 15 Jun 2026 14:22:40 +0200 Subject: [PATCH] feat: multiple words --- README.md | 5 +++-- cool_domain/__main__.py | 2 +- cool_domain/factory.py | 10 +++++++--- cool_domain/params.py | 8 ++++++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2aeb2c0..a173189 100644 --- a/README.md +++ b/README.md @@ -23,14 +23,15 @@ uvx --from git+https://git.klemek.fr/klemek/cool-domain cool-domain ## Usage ```txt -usage: cool-domain [-h] [--count DOMAIN_COUNT] [--lang {english,french}] [--dig | --no-dig] [--debug | --no-debug] [--quiet | --no-quiet] - [--cache | --no-cache] [--cache-file CACHE_FILE] [--tld-list-uri TLD_LIST_URI] +usage: cool-domain [-h] [--count DOMAIN_COUNT] [--lang {english,french}] [--words WORD_COUNT] [--dig | --no-dig] [--debug | --no-debug] + [--quiet | --no-quiet] [--cache | --no-cache] [--cache-file CACHE_FILE] [--tld-list-uri TLD_LIST_URI] options: -h, --help show this help message and exit --count DOMAIN_COUNT number of domains to generate (default: 1) --lang {english,french} word list lang (default: english) + --words WORD_COUNT number of words per domain (default: 1) --dig, --no-dig check availability with dig (default: true) --debug, --no-debug --quiet, --no-quiet diff --git a/cool_domain/__main__.py b/cool_domain/__main__.py index e8727df..4ac3d49 100644 --- a/cool_domain/__main__.py +++ b/cool_domain/__main__.py @@ -19,7 +19,7 @@ def main() -> int: TLDList(cache=cache, remote_uri=params.tld_list_uri) as tld_list, LANGS[params.lang] as word_list, ): - factory = Factory(tld_list=tld_list, word_list=word_list) + factory = Factory(tld_list=tld_list, word_list=word_list, words=params.words) logging.getLogger().info( "Searching %s domain%s", params.count, "s" if params.count > 1 else "" ) diff --git a/cool_domain/factory.py b/cool_domain/factory.py index 4a91540..4b6ba7e 100644 --- a/cool_domain/factory.py +++ b/cool_domain/factory.py @@ -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)) diff --git a/cool_domain/params.py b/cool_domain/params.py index ba17c12..fba0799 100644 --- a/cool_domain/params.py +++ b/cool_domain/params.py @@ -15,6 +15,7 @@ class Parameters: quiet: bool = False cache: bool = True count: int = 1 + words: int = 1 dig: bool = True lang: str = "english" cache_file: str = str(pathlib.Path(tempfile.gettempdir()) / ".cool-domain-cache") @@ -104,6 +105,13 @@ def parse_parameters(args: typing.Sequence[str]) -> Parameters: help="word list lang (default: english)", choices=LANGS.keys(), ) + __add_arg_int( + parser, + "--words", + env_var="WORD_COUNT", + default=default_values.words, + help_txt="number of words per domain", + ) __add_arg_bool( parser, "--dig",