diff --git a/kleinanzeigen_bot/utils.py b/kleinanzeigen_bot/utils.py index 5fe1262..1ff9abf 100644 --- a/kleinanzeigen_bot/utils.py +++ b/kleinanzeigen_bot/utils.py @@ -10,7 +10,7 @@ from datetime import datetime from types import FrameType, ModuleType, TracebackType from typing import Any, Final, TypeVar -import coloredlogs, inflect +import coloredlogs from ruamel.yaml import YAML LOG_ROOT:Final[logging.Logger] = logging.getLogger() @@ -157,23 +157,27 @@ def pause(min_ms:int = 200, max_ms:int = 2000) -> None: time.sleep(duration / 1000) -def pluralize(word:str, count:int | Sized, prefix:bool = True) -> str: +def pluralize(noun:str, count:int | Sized, prefix_with_count:bool = True) -> str: """ >>> pluralize("field", 1) '1 field' >>> pluralize("field", 2) '2 fields' - >>> pluralize("field", 2, prefix = False) + >>> pluralize("field", 2, prefix_with_count = False) 'fields' """ - if not hasattr(pluralize, "inflect"): - pluralize.inflect = inflect.engine() # type: ignore[attr-defined] # mypy if isinstance(count, Sized): count = len(count) - plural:str = pluralize.inflect.plural_noun(word, count) # type: ignore[attr-defined] # mypy - if prefix: - return f"{count} {plural}" - return plural + + prefix = f"{count} " if prefix_with_count else "" + + if count == 1: + return f"{prefix}{noun}" + if noun.endswith('s') or noun.endswith('sh') or noun.endswith('ch') or noun.endswith('x') or noun.endswith('z'): + return f"{prefix}{noun}es" + if noun.endswith('y'): + return f"{prefix}{noun[:-1]}ies" + return f"{prefix}{noun}s" def load_dict(filepath:str, content_label:str = "") -> dict[str, Any]: diff --git a/pdm.lock b/pdm.lock index 5d23332..631f9bd 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev"] strategy = ["cross_platform"] lock_version = "4.4" -content_hash = "sha256:754ee433915f73ab137d95c48897e21550161646c353b6a933700ecbc6aab7cc" +content_hash = "sha256:930f2d57b643fd0760e15f2d6122924b5b852854847f60930b3c560245ec9565" [[package]] name = "altgraph" @@ -90,15 +90,6 @@ files = [ {file = "bracex-2.4.tar.gz", hash = "sha256:a27eaf1df42cf561fed58b7a8f3fdf129d1ea16a81e1fadd1d17989bc6384beb"}, ] -[[package]] -name = "cerberus" -version = "1.3.5" -summary = "Lightweight, extensible schema and data validation tool for Pythondictionaries." -files = [ - {file = "Cerberus-1.3.5-py3-none-any.whl", hash = "sha256:7649a5815024d18eb7c6aa5e7a95355c649a53aacfc9b050e9d0bf6bfa2af372"}, - {file = "Cerberus-1.3.5.tar.gz", hash = "sha256:81011e10266ef71b6ec6d50e60171258a5b134d69f8fb387d16e4936d0d47642"}, -] - [[package]] name = "certifi" version = "2023.11.17" @@ -241,23 +232,6 @@ files = [ {file = "dill-0.3.7.tar.gz", hash = "sha256:cc1c8b182eb3013e24bd475ff2e9295af86c1a38eb1aff128dac8962a9ce3c03"}, ] -[[package]] -name = "distlib" -version = "0.3.7" -summary = "Distribution utilities" -files = [ - {file = "distlib-0.3.7-py2.py3-none-any.whl", hash = "sha256:2e24928bc811348f0feb63014e97aaae3037f2cf48712d51ae61df7fd6075057"}, - {file = "distlib-0.3.7.tar.gz", hash = "sha256:9dafe54b34a028eafd95039d5e5d4851a13734540f1331060d31c9916e7147a8"}, -] - -[[package]] -name = "docopt" -version = "0.6.2" -summary = "Pythonic argument parser, that will make you smile" -files = [ - {file = "docopt-0.6.2.tar.gz", hash = "sha256:49b3a825280bd66b3aa83585ef59c4a8c82f2c8a522dbe754a8bc8d08c85c491"}, -] - [[package]] name = "exceptiongroup" version = "1.2.0" @@ -327,20 +301,6 @@ files = [ {file = "idna-3.6.tar.gz", hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"}, ] -[[package]] -name = "inflect" -version = "7.0.0" -requires_python = ">=3.8" -summary = "Correctly generate plurals, singular nouns, ordinals, indefinite articles; convert numbers to words" -dependencies = [ - "pydantic>=1.9.1", - "typing-extensions", -] -files = [ - {file = "inflect-7.0.0-py3-none-any.whl", hash = "sha256:9544afed6182176e43955c44b1acdaed30f9b2b56c16d1fc5b222d98218b546e"}, - {file = "inflect-7.0.0.tar.gz", hash = "sha256:63da9325ad29da81ec23e055b41225795ab793b4ecb483be5dc1fa363fd4717e"}, -] - [[package]] name = "iniconfig" version = "2.0.0" @@ -353,17 +313,12 @@ files = [ [[package]] name = "isort" -version = "5.13.0" +version = "5.12.0" requires_python = ">=3.8.0" summary = "A Python utility / library to sort Python imports." -dependencies = [ - "pip-api", - "pipreqs", - "requirementslib", -] files = [ - {file = "isort-5.13.0-py3-none-any.whl", hash = "sha256:15e0e937819b350bc256a7ae13bb25f4fe4f8871a0bc335b20c3627dba33f458"}, - {file = "isort-5.13.0.tar.gz", hash = "sha256:d67f78c6a1715f224cca46b29d740037bdb6eea15323a133e897cda15876147b"}, + {file = "isort-5.12.0-py3-none-any.whl", hash = "sha256:f84c2818376e66cf843d497486ea8fed8700b340f308f076c6fb1229dff318b6"}, + {file = "isort-5.12.0.tar.gz", hash = "sha256:8bef7dde241278824a6d83f44a544709b065191b95b6e50894bdc722fcba0504"}, ] [[package]] @@ -504,56 +459,6 @@ files = [ {file = "pefile-2023.2.7.tar.gz", hash = "sha256:82e6114004b3d6911c77c3953e3838654b04511b8b66e8583db70c65998017dc"}, ] -[[package]] -name = "pep517" -version = "0.13.1" -requires_python = ">=3.6" -summary = "Wrappers to build Python packages using PEP 517 hooks" -dependencies = [ - "tomli>=1.1.0; python_version < \"3.11\"", -] -files = [ - {file = "pep517-0.13.1-py3-none-any.whl", hash = "sha256:31b206f67165b3536dd577c5c3f1518e8fbaf38cbc57efff8369a392feff1721"}, - {file = "pep517-0.13.1.tar.gz", hash = "sha256:1b2fa2ffd3938bb4beffe5d6146cbcb2bda996a5a4da9f31abffd8b24e07b317"}, -] - -[[package]] -name = "pip" -version = "23.3.1" -requires_python = ">=3.7" -summary = "The PyPA recommended tool for installing Python packages." -files = [ - {file = "pip-23.3.1-py3-none-any.whl", hash = "sha256:55eb67bb6171d37447e82213be585b75fe2b12b359e993773aca4de9247a052b"}, - {file = "pip-23.3.1.tar.gz", hash = "sha256:1fcaa041308d01f14575f6d0d2ea4b75a3e2871fe4f9c694976f908768e14174"}, -] - -[[package]] -name = "pip-api" -version = "0.0.30" -requires_python = ">=3.7" -summary = "An unofficial, importable pip API" -dependencies = [ - "pip", -] -files = [ - {file = "pip-api-0.0.30.tar.gz", hash = "sha256:a05df2c7aa9b7157374bcf4273544201a0c7bae60a9c65bcf84f3959ef3896f3"}, - {file = "pip_api-0.0.30-py3-none-any.whl", hash = "sha256:2a0314bd31522eb9ffe8a99668b0d07fee34ebc537931e7b6483001dbedcbdc9"}, -] - -[[package]] -name = "pipreqs" -version = "0.4.13" -requires_python = ">=3.7" -summary = "Pip requirements.txt generator based on imports in project" -dependencies = [ - "docopt", - "yarg", -] -files = [ - {file = "pipreqs-0.4.13-py2.py3-none-any.whl", hash = "sha256:e522b9ed54aa3e8b7978ff251ab7a9af2f75d2cd8de4c102e881b666a79a308e"}, - {file = "pipreqs-0.4.13.tar.gz", hash = "sha256:a17f167880b6921be37533ce4c81ddc6e22b465c107aad557db43b1add56a99b"}, -] - [[package]] name = "platformdirs" version = "4.1.0" @@ -564,34 +469,6 @@ files = [ {file = "platformdirs-4.1.0.tar.gz", hash = "sha256:906d548203468492d432bcb294d4bc2fff751bf84971fbb2c10918cc206ee420"}, ] -[[package]] -name = "plette" -version = "0.4.4" -requires_python = ">=3.7" -summary = "Structured Pipfile and Pipfile.lock models." -dependencies = [ - "tomlkit", -] -files = [ - {file = "plette-0.4.4-py2.py3-none-any.whl", hash = "sha256:42d68ce8c6b966874b68758d87d7f20fcff2eff0d861903eea1062126be4d98f"}, - {file = "plette-0.4.4.tar.gz", hash = "sha256:06b8c09eb90293ad0b8101cb5c95c4ea53e9b2b582901845d0904ff02d237454"}, -] - -[[package]] -name = "plette" -version = "0.4.4" -extras = ["validation"] -requires_python = ">=3.7" -summary = "Structured Pipfile and Pipfile.lock models." -dependencies = [ - "cerberus", - "plette==0.4.4", -] -files = [ - {file = "plette-0.4.4-py2.py3-none-any.whl", hash = "sha256:42d68ce8c6b966874b68758d87d7f20fcff2eff0d861903eea1062126be4d98f"}, - {file = "plette-0.4.4.tar.gz", hash = "sha256:06b8c09eb90293ad0b8101cb5c95c4ea53e9b2b582901845d0904ff02d237454"}, -] - [[package]] name = "pluggy" version = "1.3.0" @@ -783,7 +660,7 @@ files = [ [[package]] name = "pylint" -version = "3.0.2" +version = "3.0.3" requires_python = ">=3.8.0" summary = "python code static checker" dependencies = [ @@ -792,15 +669,15 @@ dependencies = [ "dill>=0.2; python_version < \"3.11\"", "dill>=0.3.6; python_version >= \"3.11\"", "dill>=0.3.7; python_version >= \"3.12\"", - "isort<6,>=4.2.5", + "isort!=5.13.0,<6,>=4.2.5", "mccabe<0.8,>=0.6", "platformdirs>=2.2.0", "tomli>=1.1.0; python_version < \"3.11\"", "tomlkit>=0.10.1", ] files = [ - {file = "pylint-3.0.2-py3-none-any.whl", hash = "sha256:60ed5f3a9ff8b61839ff0348b3624ceeb9e6c2a92c514d81c9cc273da3b6bcda"}, - {file = "pylint-3.0.2.tar.gz", hash = "sha256:0d4c286ef6d2f66c8bfb527a7f8a629009e42c99707dec821a03e1b51a4c1496"}, + {file = "pylint-3.0.3-py3-none-any.whl", hash = "sha256:7a1585285aefc5165db81083c3e06363a27448f6b467b3b0f30dbd0ac1f73810"}, + {file = "pylint-3.0.3.tar.gz", hash = "sha256:58c2398b0301e049609a8429789ec6edf3aabe9b6c5fec916acd18639c16de8b"}, ] [[package]] @@ -922,27 +799,6 @@ files = [ {file = "requests-2.31.0.tar.gz", hash = "sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1"}, ] -[[package]] -name = "requirementslib" -version = "3.0.0" -requires_python = ">=3.7" -summary = "A tool for converting between pip-style and pipfile requirements." -dependencies = [ - "distlib>=0.2.8", - "pep517>=0.5.0", - "pip>=23.1", - "platformdirs", - "plette[validation]", - "pydantic", - "requests", - "setuptools>=40.8", - "tomlkit>=0.5.3", -] -files = [ - {file = "requirementslib-3.0.0-py2.py3-none-any.whl", hash = "sha256:67b42903d7c32f89c7047d1020c619d37cb515c475a4ae6f4e5683e1c56d7bf7"}, - {file = "requirementslib-3.0.0.tar.gz", hash = "sha256:28f8e0b1c38b34ae06de68ef115b03bbcdcdb99f9e9393333ff06ded443e3f24"}, -] - [[package]] name = "rich" version = "13.7.0" @@ -1222,15 +1078,3 @@ files = [ {file = "wsproto-1.2.0-py3-none-any.whl", hash = "sha256:b9acddd652b585d75b20477888c56642fdade28bdfd3579aa24a4d2c037dd736"}, {file = "wsproto-1.2.0.tar.gz", hash = "sha256:ad565f26ecb92588a3e43bc3d96164de84cd9902482b130d0ddbaa9664a85065"}, ] - -[[package]] -name = "yarg" -version = "0.1.9" -summary = "A semi hard Cornish cheese, also queries PyPI (PyPI client)" -dependencies = [ - "requests", -] -files = [ - {file = "yarg-0.1.9-py2.py3-none-any.whl", hash = "sha256:4f9cebdc00fac946c9bf2783d634e538a71c7d280a4d806d45fd4dc0ef441492"}, - {file = "yarg-0.1.9.tar.gz", hash = "sha256:55695bf4d1e3e7f756496c36a69ba32c40d18f821e38f61d028f6049e5e15911"}, -] diff --git a/pyproject.toml b/pyproject.toml index 4984285..b07d7a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,6 @@ classifiers = [ # https://pypi.org/classifiers/ requires-python = ">=3.10,<3.13" # <3.12 required for pyinstaller dependencies = [ "coloredlogs~=15.0", - "inflect~=7.0", "overrides~=7.4", "ruamel.yaml~=0.18", "pywin32==306; sys_platform == 'win32'",