diff --git a/README.md b/README.md index 7fee0c8..a950e9c 100644 --- a/README.md +++ b/README.md @@ -212,8 +212,8 @@ ad_defaults: active: true type: # one of: OFFER, WANTED description: - prefix: - suffix: + prefix: "" + suffix: "" price_type: # one of: FIXED, NEGOTIABLE, GIVE_AWAY shipping_type: # one of: PICKUP, SHIPPING, NOT_APPLICABLE contact: @@ -239,11 +239,12 @@ browser: # --headless # --start-maximized binary_location: # path to custom browser executable, if not specified will be looked up on PATH + extensions: [] # a list of .crx extension files to be loaded # login credentials login: - username: - password: + username: "" + password: "" ``` diff --git a/kleinanzeigen_bot/__init__.py b/kleinanzeigen_bot/__init__.py index ba5cbdb..4b6251d 100644 --- a/kleinanzeigen_bot/__init__.py +++ b/kleinanzeigen_bot/__init__.py @@ -272,6 +272,7 @@ class KleinanzeigenBot(SeleniumMixin): self.browser_arguments = self.config["browser"]["arguments"] self.browser_binary_location = self.config["browser"]["binary_location"] + self.browser_extensions = [ abspath(item, relative_to = self.config_file_path) for item in self.config["browser"]["extensions"] ] def login(self) -> None: LOG.info("Logging in as [%s]...", self.config["login"]["username"]) diff --git a/kleinanzeigen_bot/resources/config_defaults.yaml b/kleinanzeigen_bot/resources/config_defaults.yaml index bee4195..ab36d84 100644 --- a/kleinanzeigen_bot/resources/config_defaults.yaml +++ b/kleinanzeigen_bot/resources/config_defaults.yaml @@ -3,23 +3,27 @@ ad_files: - "**/ad_*.yml" - "**/ad_*.yaml" +# default values for ads, can be overwritten in each ad configuration file ad_defaults: active: true - type: OFFER + type: OFFER # one of: OFFER, WANTED description: prefix: "" suffix: "" - price_type: NEGOTIABLE - shipping_type: SHIPPING + price_type: NEGOTIABLE # one of: FIXED, NEGOTIABLE, GIVE_AWAY + shipping_type: SHIPPING # one of: PICKUP, SHIPPING, NOT_APPLICABLE contact: name: "" street: "" zipcode: phone: "" # IMPORTANT: surround phone number with quotes to prevent removal of leading zeros - republication_interval: 7 + republication_interval: 7 # every X days ads should be re-published +# additional name to category ID mappings, see default list at +# https://github.com/Second-Hand-Friends/kleinanzeigen-bot/blob/main/kleinanzeigen_bot/resources/categories.yaml categories: [] +# browser configuration browser: # https://peter.sh/experiments/chromium-command-line-switches/ arguments: @@ -28,8 +32,10 @@ browser: - --no-sandbox # --headless # --start-maximized - binary_location: + binary_location: # path to custom browser executable, if not specified will be looked up on PATH + extensions: [] # a list of .crx extension files to be loaded +# login credentials login: - username: "" + username: "" password: "" diff --git a/kleinanzeigen_bot/selenium_mixin.py b/kleinanzeigen_bot/selenium_mixin.py index c1fe99c..a18f6da 100644 --- a/kleinanzeigen_bot/selenium_mixin.py +++ b/kleinanzeigen_bot/selenium_mixin.py @@ -35,6 +35,7 @@ class SeleniumMixin: def __init__(self): self.browser_arguments:Iterable[str] = [] self.browser_binary_location:str = None + self.browser_extensions:Iterable[str] = [] self.webdriver:WebDriver = None def create_webdriver_session(self) -> None: @@ -54,6 +55,11 @@ class SeleniumMixin: browser_options.add_argument(chrome_option) LOG.debug("Effective browser arguments: %s", browser_options.arguments) + for crx_extension in self.browser_extensions: + ensure(os.path.exists(crx_extension), f"Configured extension-file [{crx_extension}] does not exist.") + browser_options.add_extension(crx_extension) + LOG.debug("Effective browser extensions: %s", browser_options.extensions) + browser_options.add_experimental_option("excludeSwitches", ["enable-automation"]) browser_options.add_experimental_option("useAutomationExtension", False) browser_options.add_experimental_option("prefs", {