kacpi2442 / am_bot

Using the toogoodtogo and foodsi APIs to notify me via a Telegram bot for open offers
39 stars 19 forks source link

Can you give me a clue.. #15

Closed swiezaczek closed 1 year ago

swiezaczek commented 1 year ago

.. how to edit script to run automatically another file (simple bat that change mac and restart internet connection) when I get error 403(captcha) and then how to continue running script without starting it from the beginning (when connection drops the scrips shuts down). This way I can scrap again and with very small interval, but for now my method is just to restart the script with this bat file ( I get notifications for the items I already received notifications for unfortunately):

bat file content:

cd C:\Program Files (x86)\Technitium\TMACv6.0
start TMAC.exe -n Wi-Fi -r -re -s
TIMEOUT /T 5 >nul
netsh wlan connect ssid=<ssid> name=<name>
cd C:\<bot path>
start watch_script.bat
exit

watch_script.bat content: powershell py watch_script.py

I found this piece of code in another watcher, but I dont know how to edit it to run bat file instead of going to sleep and dont know how to implement it to your bot to do expected job for me:

   def run(self) -> NoReturn:
        """
        Main Loop of the Scanner
        """
        log.info("Scanner started ...")
        while True:
            if self.cron.is_now:
                try:
                    self._job()
                    if self.tgtg_client.captcha_error_count > 10:
                        log.warning("Too many 403 Errors. Sleeping for 1 hour.")
                        sleep(60 * 60)
                        log.info("Continuing scanning.")
                        self.tgtg_client.captcha_error_count = 0
                except Exception:
                    log.error("Job Error! - %s", sys.exc_info())
            sleep(self.config.sleep_time * (0.9 + 0.2 * random()))