feat: allow auto-restart on captcha (#481)

Co-authored-by: sebthom <sebthom@users.noreply.github.com>
This commit is contained in:
Airwave1981
2025-04-26 14:40:47 +02:00
committed by GitHub
parent 4891c142a9
commit d87ae6e740
6 changed files with 67 additions and 6 deletions

View File

@@ -3,7 +3,23 @@ SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
"""
import sys
import kleinanzeigen_bot
import sys, time
from gettext import gettext as _
kleinanzeigen_bot.main(sys.argv)
import kleinanzeigen_bot
from kleinanzeigen_bot.utils.exceptions import CaptchaEncountered
from kleinanzeigen_bot.utils.misc import format_timedelta
# --------------------------------------------------------------------------- #
# Main loop: run bot → if captcha → sleep → restart
# --------------------------------------------------------------------------- #
while True:
try:
kleinanzeigen_bot.main(sys.argv) # runs & returns when finished
sys.exit(0) # not using `break` to prevent process closing issues
except CaptchaEncountered as ex:
delay = ex.restart_delay
print(_("[INFO] Captcha detected. Sleeping %s before restart...") % format_timedelta(delay))
time.sleep(delay.total_seconds())
# loop continues and starts a fresh run