mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 10:31:50 +01:00
feat: allow auto-restart on captcha (#481)
Co-authored-by: sebthom <sebthom@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user