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
def navigate_waypoint(self, driver, waypoint, timeout): log.info('Navigating ' + str(waypoint)) elem = get_element(driver, waypoint.locator, timeout=timeout) jitter(.8) elem.click() try: WebDriverWait(driver, timeout).until(EC.staleness_of(elem)) except TimeoutException: pass if remove_qs(driver.current_url) == BASE_URL + waypoint.dest: log.info("Navigated to '{}'".format(waypoint.dest)) else: raise NavigationException("Navigation to '{}' failed".format( waypoint.dest))
def polar_dot(thetas, at=1, color='C0', jitter=0, ax=None, **kwargs): """Plots points onto the outside of a polar Axes. Parameters ---------- thetas : 1D array-like Angular values to plot. at : int or float (optional, default=1) Position (r-value, along radial axis) to plot points. color : valid matplotlib color (optional, default='C0') Color of dots. jitter : float (optional, default=0) How much jitter should be applid to r-value for plotting dots? ax : matplotlib Axes handle (optional, default=None) Axes to plot dots. If `ax` is passed, make sure that it is already formatted in polar coordinates! **kwargs : keyword arguments to be passed to ax.scatter() Returns ------- fig, ax : matplotlib Figure & Axes handle. """ thetas = np.asarray(thetas) if ax is None: fig, ax = plt.subplots(subplot_kw=dict(polar=True)) else: fig = plt.gcf() rs = utils.jitter(at=at, size=thetas.size, spread=jitter) ax.scatter(thetas, rs, color=color, **kwargs) return fig, ax
log.info('Successfully logged in via stored session data') else: log.error('Error logging in with stored session data') wait_for_auth(driver) # v-- Change this dynamically when more site configs exist site_config = config.WholeFoods # Navigate from BASE_URL to SLOT_URL 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)