mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 10:31:50 +01:00
Fixes #12 add --force flag
This commit is contained in:
@@ -43,6 +43,7 @@ class KleinanzeigenBot(SeleniumMixin):
|
|||||||
self.log_file_path = os.path.join(os.getcwd(), f"{log_file_basename}.log")
|
self.log_file_path = os.path.join(os.getcwd(), f"{log_file_basename}.log")
|
||||||
|
|
||||||
self.command = "help"
|
self.command = "help"
|
||||||
|
self.force_mode = False
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if self.file_log:
|
if self.file_log:
|
||||||
@@ -68,7 +69,7 @@ class KleinanzeigenBot(SeleniumMixin):
|
|||||||
case "publish":
|
case "publish":
|
||||||
self.configure_file_logging()
|
self.configure_file_logging()
|
||||||
self.load_config()
|
self.load_config()
|
||||||
if ads := self.load_ads():
|
if ads := self.load_ads(exclude_undue = not self.force_mode):
|
||||||
self.create_webdriver_session()
|
self.create_webdriver_session()
|
||||||
self.login()
|
self.login()
|
||||||
self.publish_ads(ads)
|
self.publish_ads(ads)
|
||||||
@@ -90,7 +91,7 @@ class KleinanzeigenBot(SeleniumMixin):
|
|||||||
exe = "python -m kleinanzeigen_bot"
|
exe = "python -m kleinanzeigen_bot"
|
||||||
|
|
||||||
print(textwrap.dedent(f"""\
|
print(textwrap.dedent(f"""\
|
||||||
Usage: {exe} COMMAND [-v|--verbose] [--config=<PATH>] [--logfile=<PATH>]
|
Usage: {exe} COMMAND [--config=<PATH>] [--force] [--logfile=<PATH>] [-v|--verbose]
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
publish - (re-)publishes ads
|
publish - (re-)publishes ads
|
||||||
@@ -98,11 +99,17 @@ class KleinanzeigenBot(SeleniumMixin):
|
|||||||
--
|
--
|
||||||
help - displays this help (default command)
|
help - displays this help (default command)
|
||||||
version - displays the application version
|
version - displays the application version
|
||||||
|
|
||||||
|
Flags:
|
||||||
|
--config=<PATH> - path to the config YAML or JSON file (default: ./config.yaml)
|
||||||
|
--force - republish all ads ignoring republication_interval
|
||||||
|
--logfile=<PATH> - path to the logfile (default: ./kleinanzeigen-bot.log)
|
||||||
|
-v, --verbose - enables verbose output - only useful when troubleshooting issues
|
||||||
"""))
|
"""))
|
||||||
|
|
||||||
def parse_args(self, args:Iterable[str]) -> None:
|
def parse_args(self, args:Iterable[str]) -> None:
|
||||||
try:
|
try:
|
||||||
options, arguments = getopt.gnu_getopt(args[1:], "hv", ["help", "verbose", "logfile=", "config="]) # pylint: disable=unused-variable
|
options, arguments = getopt.gnu_getopt(args[1:], "hv", ["help", "verbose", "force", "logfile=", "config="]) # pylint: disable=unused-variable
|
||||||
except getopt.error as ex:
|
except getopt.error as ex:
|
||||||
LOG.error(ex.msg)
|
LOG.error(ex.msg)
|
||||||
LOG.error("Use --help to display available options")
|
LOG.error("Use --help to display available options")
|
||||||
@@ -120,6 +127,8 @@ class KleinanzeigenBot(SeleniumMixin):
|
|||||||
self.log_file_path = os.path.abspath(value)
|
self.log_file_path = os.path.abspath(value)
|
||||||
else:
|
else:
|
||||||
self.log_file_path = None
|
self.log_file_path = None
|
||||||
|
case "--force":
|
||||||
|
self.force_mode = True
|
||||||
case "-v" | "--verbose":
|
case "-v" | "--verbose":
|
||||||
LOG.setLevel(logging.DEBUG)
|
LOG.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
@@ -146,7 +155,7 @@ class KleinanzeigenBot(SeleniumMixin):
|
|||||||
|
|
||||||
LOG.info("App version: %s", self.get_version())
|
LOG.info("App version: %s", self.get_version())
|
||||||
|
|
||||||
def load_ads(self, exclude_inactive = True, exclude_undue = True) -> Iterable[dict[str, Any]]:
|
def load_ads(self, *, exclude_inactive = True, exclude_undue = True) -> Iterable[dict[str, Any]]:
|
||||||
LOG.info("Searching for ad files...")
|
LOG.info("Searching for ad files...")
|
||||||
|
|
||||||
ad_files = set()
|
ad_files = set()
|
||||||
|
|||||||
Reference in New Issue
Block a user