allow configuration of additional browser extensions

This commit is contained in:
sebthom
2022-02-17 13:08:09 +01:00
parent b879e3d6db
commit 7ee2d533df
4 changed files with 24 additions and 10 deletions

View File

@@ -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: ""
```

View File

@@ -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"])

View File

@@ -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: ""
password: ""

View File

@@ -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", {