fix: set custom shipping due css update #448 (#450)

This commit is contained in:
Heavenfighter
2025-03-13 12:13:23 +01:00
committed by GitHub
parent 6bd5ba98d2
commit 7742196043
2 changed files with 21 additions and 17 deletions

View File

@@ -17,13 +17,13 @@ from ruamel.yaml import YAML
from wcmatch import glob from wcmatch import glob
from . import extract, resources from . import extract, resources
from ._version import __version__
from .ads import calculate_content_hash, get_description_affixes from .ads import calculate_content_hash, get_description_affixes
from .utils import dicts, error_handlers, loggers, misc from .utils import dicts, error_handlers, loggers, misc
from .utils.files import abspath from .utils.files import abspath
from .utils.i18n import Locale, get_current_locale, set_current_locale, pluralize from .utils.i18n import Locale, get_current_locale, pluralize, set_current_locale
from .utils.misc import ainput, ensure, is_frozen, parse_datetime, parse_decimal from .utils.misc import ainput, ensure, is_frozen, parse_datetime, parse_decimal
from .utils.web_scraping_mixin import By, Element, Page, Is, WebScrapingMixin from .utils.web_scraping_mixin import By, Element, Is, Page, WebScrapingMixin
from ._version import __version__
# W0406: possibly a bug, see https://github.com/PyCQA/pylint/issues/3933 # W0406: possibly a bug, see https://github.com/PyCQA/pylint/issues/3933
@@ -928,23 +928,24 @@ class KleinanzeigenBot(WebScrapingMixin):
await self.web_click(By.CSS_SELECTOR, '[class*="CarrierSelectionModal"]') await self.web_click(By.CSS_SELECTOR, '[class*="CarrierSelectionModal"]')
await self.__set_shipping_options(ad_cfg) await self.__set_shipping_options(ad_cfg)
else: else:
try: special_shipping_selector = '//select[contains(@id, ".versand_s")]'
special_shipping_selector = '//select[contains(@id, ".versand_s")]' if await self.web_check(By.XPATH, special_shipping_selector, Is.DISPLAYED):
if await self.web_check(By.XPATH, special_shipping_selector, Is.DISPLAYED): # try to set special attribute selector (then we have a commercial account)
# try to set special attribute selector (then we have a commercial account) shipping_value = "ja" if ad_cfg["shipping_type"] == "SHIPPING" else "nein"
shipping_value = "ja" if ad_cfg["shipping_type"] == "SHIPPING" else "nein" await self.web_select(By.XPATH, special_shipping_selector, shipping_value)
await self.web_select(By.XPATH, special_shipping_selector, shipping_value) elif ad_cfg["shipping_costs"]:
else: try:
# no options. only costs. Set custom shipping cost
await self.web_click(By.XPATH, await self.web_click(By.XPATH,
'//*[contains(@class, "SubSection")]//*//button[contains(@class, "SelectionButton")]') '//*[contains(@class, "SubSection")]//*//button[contains(@class, "SelectionButton")]')
await self.web_click(By.CSS_SELECTOR, '[class*="CarrierSelectionModal"]') await self.web_click(By.XPATH, '//*[contains(@class, "CarrierSelectionModal")]//button[contains(text(),"Andere Versandmethoden")]')
await self.web_click(By.CSS_SELECTOR, '[class*="CarrierOption--Main"]') await self.web_click(By.XPATH, '//*[contains(@class, "CarrierOption--Main") and contains(@data-testid, "Individueller Versand")]')
if ad_cfg["shipping_costs"]: await self.web_input(By.CSS_SELECTOR, '.IndividualShippingInput input[type="text"]',
await self.web_input(By.CSS_SELECTOR, '.IndividualShippingInput input[type="text"]', str.replace(ad_cfg["shipping_costs"], ".", ",") str.replace(ad_cfg["shipping_costs"], ".", ","))
)
await self.web_click(By.XPATH, '//*[contains(@class, "ModalDialog--Actions")]//button[.//*[text()[contains(.,"Fertig")]]]') await self.web_click(By.XPATH, '//*[contains(@class, "ModalDialog--Actions")]//button[.//*[text()[contains(.,"Fertig")]]]')
except TimeoutError as ex: except TimeoutError as ex:
LOG.debug(ex, exc_info = True) LOG.debug(ex, exc_info = True)
raise TimeoutError(_("Unable to close shipping dialog!")) from ex
async def __set_shipping_options(self, ad_cfg: dict[str, Any]) -> None: async def __set_shipping_options(self, ad_cfg: dict[str, Any]) -> None:
shipping_options_mapping = { shipping_options_mapping = {

View File

@@ -128,6 +128,9 @@ kleinanzeigen_bot/__init__.py:
fill_login_data_and_send: fill_login_data_and_send:
"Logging in as [%s]...": "Anmeldung als [%s]..." "Logging in as [%s]...": "Anmeldung als [%s]..."
__set_shipping:
"Unable to close shipping dialog!": "Versanddialog konnte nicht geschlossen werden!"
__set_shipping_options: __set_shipping_options:
"Unable to close shipping dialog!": "Versanddialog konnte nicht geschlossen werden!" "Unable to close shipping dialog!": "Versanddialog konnte nicht geschlossen werden!"