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
# 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) else: try: # Allow time to check out manually sleep(900) except KeyboardInterrupt: log.warning('Slumber disturbed')
time = item["datetime"]["time"] # If location is there in the event, append to the update else leave it if "locationAddr" in item: progress = item["descEn"] + ' at ' + item["locationAddr"]["city"] + ',' + \ item["locationAddr"]["countryNmEn"] else: progress = item["descEn"] row = [date, time, progress] package_progress_list.append(row) logger.log_note( 'List of events for the email message body created') # Format the email body to html format body = response_format.html_result(package_progress_list) logger.log_note('Email body formatted to html') # Send notification for every new event notify.send_sms('Canada Post status update pkg # ' + config['Default']['tracking_number'] + ' - ' + sms_msg, \ config['Default']['account_sid'], config['Default']['auth_token']) logger.log_note('SMS for the new event sent') notify.send_email('Canada Post status update pkg # ' + config['Default']['tracking_number'], body, \ config['Default']['sendgrid_key']) logger.log_note( 'Email for the list of events along with the new event sent' ) # Update the last_event_count config.set('Default', 'last_event_count', str(event_count)) with open('config.ini', 'w') as configfile: config.write(configfile) logger.log_note( 'New event count is updated in config file as ' + str(event_count)) # Log message that the job has completed logger.log_note('*** Job completed at ' +