Example #1
0
def main_loop(driver, args):
    log.info('Reading slot preferences from conf')
    slot_prefs = get_prefs_from_conf()
    log.info('Navigating to ' + config.BASE_URL)
    driver.get(config.BASE_URL)

    if args.force_login or not os.path.exists(config.PKL_PATH):
        # Login and capture Amazon session data...
        wait_for_auth(driver)
    else:
        # ...or load from storage
        load_session_data(driver)
        driver.refresh()
        if is_logged_in(driver):
            log.info('Successfully logged in via stored session data')
        else:
            log.error('Error logging in with stored session data')
            wait_for_auth(driver)
    site_config = config.SiteConfig(args.service)
    # Navigate to slot select
    build_route(site_config, 'SLOT_SELECT').navigate(driver)
    slots = slots_available(driver, slot_prefs)
    if slots:
        annoy()
        alert('Delivery slots available. What do you need me for?', 'Sosumi')
    while not slots:
        log.info('No slots found :( waiting...')
        jitter(25)
        driver.refresh()
        slots = slots_available(driver, slot_prefs)
        if slots:
            alert('Delivery slots found')
            message_body = generate_message(slots, args.service, args.checkout)
            send_sms(message_body)
            send_telegram(message_body)
            if not args.checkout:
                break
            checked_out = False
            log.info('Attempting to select slot and checkout')
            while not checked_out:
                try:
                    log.info('Selecting slot: ' + slots[0].full_name)
                    slots[0].select(driver)
                    build_route(site_config, 'CHECKOUT').navigate(driver)
                    checked_out = True
                    alert('Checkout complete', 'Hero')
                except RouteRedirectException:
                    log.warning('Checkout failed: Redirected to slot select')
                    slots = slots_available(driver, slot_prefs)
                    if not slots:
                        break
Example #2
0
 site_config.Routes.SLOT_SELECT.navigate(driver)
 # Check for delivery slots
 slots = slots_available(driver, site_config, slot_prefs)
 if slots:
     annoy()
     alert('Delivery slots available. What do you need me for?', 'Sosumi')
 while not slots:
     log.info('No slots found :( waiting...')
     jitter(25)
     driver.refresh()
     slots = slots_available(driver, site_config, slot_prefs)
     if slots:
         alert('Delivery slots found')
         message_body = generate_message(slots, args.checkout)
         send_sms(message_body)
         send_telegram(message_body)
         break
 if args.checkout:
     log.info('Attempting to select slot and checkout')
     log.info('Selecting slot: ' + slots[0].full_name)
     slots[0].select(driver)
     site_config.Routes.CHECKOUT.navigate(driver)
     alert('Checkout complete', 'Hero')
     sleep(60)
 else:
     try:
         # Allow time to check out manually
         sleep(900)
     except KeyboardInterrupt:
         log.warning('Slumber disturbed')
 log.info('Closing webdriver')