Exemple #1
0
 def alert_available(self):
     """ Alert, Termin verfügbar! Und Exit """
     self.logger.warning('Available appointments!')
     alert = settings.ALERT_AVAILABLE.replace('{{ LOCATION }}',
                                              self.location_full)
     #alert = alert.replace('{{ APPOINTMENTS }}', '  \n'.join(self.parse_appointments()))
     send_alert(alert)
     sleep(settings.WAIT_SMS_MANUAL)
     self.keep_browser = True
     self.logger.warning(
         'Exiting in 10 minutes, our job here is done. Keeping browser open.'
     )
     sleep(600)
     exit()
Exemple #2
0
 def alert_sms(self) -> str:
     """ Benachrichtigung User - um entweder SMS Code via ext. Plattform (Zulip, ...)
     oder manuell einzugeben. Wartet max. 10 Minuten, und fährt dann fährt dann fort """
     self.logger.warning('Enter SMS code! Waiting for user input.')
     send_alert(
         settings.ALERT_SMS.replace('{{ LOCATION }}', self.location_full))
     start = time()
     while (time() - start) < settings.WAIT_SMS_MANUAL:
         _code = read_backend('sms')
         if _code:
             self.logger.warning(
                 f'Received Code from backend: {_code} - entering now...')
             send_alert(f'Entering code "{_code}"; check your mails!  \n'
                        f'Thanks for using RAUSYS Technologies :)')
             return _code
         sleep(15)
     self.logger.warning('No SMS code received from backend')
Exemple #3
0
 def control_sms(self) -> None:
     """ 2/2 Kontrollfunktion um Vermittlungscode zu beziehen """
     self.logger.warning(
         f'We have vacancy! Requesting Vermittlungscode for {self.driver.current_url}'
     )
     self.claim_code()
     if self.register_limit_reached:
         self.logger.error(
             'Request limit reached - try using a different phone number and email'
         )
         send_alert(
             f'Server [{self.server_id}] returned max. requests. Consider changing phone number and email'
         )
         return
     sms_code = self.alert_sms()
     self.enter_sms(sms_code)
     self.logger.info(
         'Add the code you got via mail to settings.py and restart the script!'
     )
Exemple #4
0
    def alert_appointment(self) -> None:
        """ Benachrichtigung User - um entweder Termin via ext. Plattform (Zulip, ...) zu buchen
        oder manuell einzugeben. Kritischste Funktion – max. Exception-Verschachtelung """
        self.logger.warning('Available appointments! Waiting for user input')
        alert = settings.ALERT_AVAILABLE\
            .replace('{{ LOCATION }}', self.location_full)\
            .replace('{{ LINK }}', self.driver.current_url)
        send_alert(alert)
        self.keep_browser = True

        if not settings.BOOK_REMOTELY:
            self.logger.warning(
                'Exiting in 10 minutes, our job here is done. Keeping browser open.'
            )
            return

        try:
            self.remote_booking()
        except:
            self.logger.exception(
                'Unexpected exception occurred trying to book appointments remotely!'
            )
            send_alert(
                'Appointment could not be booked – please continue manually!')
Exemple #5
0
    def remote_booking(self) -> None:
        """ Hilfsfunktion um Termine Remote zu buchen – wartet auf max 10 Minuten
        auf User Input via Chat App und fährt dann fährt dann fort """
        # Booking remotely - should probably be a dedicated function
        api = API(driver=self)
        appointments = api.control_appointments()

        if not appointments:
            self.logger.warning(
                'BOOK_REMOTELY enabled, but appointments empty! Please continue manually'
            )
            send_alert(
                'Booking remotely enabled, but didn\'t get appointments from backend. Please continue manually!'
            )
            return

        fappointments = format_appointments(appointments.get('termine'))
        send_alert(
            settings.ALERT_BOOKINGS.replace('{{ APPOINTMENTS }}',
                                            '  \n'.join(fappointments)))

        start = time()
        while (time() - start) < settings.WAIT_SMS_MANUAL:
            _code = read_backend('appt')
            if _code:
                self.logger.warning(
                    f'Received Appointment indicator from backend: {_code} - booking now...'
                )
                if api.book_appointment(appointments,
                                        int(_code)) or self.book_appointment(
                                            int(_code)):
                    appointment = fappointments[int(_code) - 1].replace(
                        "* ", "").replace(f' (appt:{_code})', '')
                    send_alert(
                        f'Successfully booked appointment "**{appointment}**" – check your mails!  \n'
                        f'Thanks for using RAUSYS Technologies :)  \n'
                        f'Feedback is highly appreciated: '
                        f'https://github.com/alfonsrv/impf-botpy/issues/1 and only takes 2 seconds!'
                    )
                    self.logger.info(
                        'Booking confirmed! Feedback is highly appreciated: '
                        'https://github.com/alfonsrv/impf-botpy/issues/1 and only takes 2 seconds!'
                    )
                    return
                raise Exception('Did not get <201 Created> from server')
            sleep(15)

        self.logger.warning('No Appointment indicator received from backend')
Exemple #6
0
                        action='store_true')
    parser.add_argument('--surf',
                        help='Interactive Surf Session for Cookie Enrichment',
                        action='store_true')
    parser.add_argument('--version',
                        help='Print version and exit',
                        action='store_true')
    args = parser.parse_args()

    if args.version:
        print_version()
        exit()
    if args.alerts:
        print_config()
        send_alert(
            'Notification test from Impf Bot.py - https://github.com/alfonsrv/impf-botpy'
        )
        exit()

    logger.info(
        f'Starting up Impf Bot.py - github/@alfonsrv, 05/2021 (version {v})')
    if args.code:
        instant_code()
        exit()
    if args.manual:
        print('Try in combination with --code')
        exit()
    elif args.surf:
        x = Browser(location='', code='')
        input('Press Enter to end interactive session')
        x.driver.quit()
Exemple #7
0
    logger.info(f'Waiting until {(datetime.now() + timedelta(seconds=settings.WAIT_LOCATIONS)).strftime("%H:%M:%S")} '
                f'before checking the next location')
    sleep(settings.WAIT_LOCATIONS)
    if not x.keep_browser: x.driver.close()
    return location


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--alerts', help='Check all alert backends and exit', action='store_true')
    parser.add_argument('--version', help='Print version and exit', action='store_true')
    args = parser.parse_args()

    if args.version: print_version(); exit()
    if args.alerts: print_config(); send_alert('Notification test from Impf Bot.py - https://github.com/alfonsrv/impf-botpy'); exit()

    logger.info('Starting up Impf Bot.py - github/@alfonsrv, 05/2021')
    print_config()

    while True:
        if settings.CONCURRENT_ENABLED:
            logger.info(f'CONCURRENT_ENABLED set with {settings.CONCURRENT_WORKERS} simultaneous workers')
            logger.info(f'Spawning Browsers with {settings.WAIT_CONCURRENT}s delay.')
            locations = settings.LOCATIONS
            with concurrent.futures.ThreadPoolExecutor(max_workers=settings.CONCURRENT_WORKERS) as executor:
                #futures = [executor.submit(impf_me, location) for location in settings.LOCATIONS]10
                futures = []
                for location in settings.LOCATIONS:
                    futures.append(executor.submit(impf_me, location))
                    sleep(30)