diff --git a/config.ini b/config.ini index 179d05e..1fbeec8 100644 --- a/config.ini +++ b/config.ini @@ -6,6 +6,7 @@ working_directory = ./tmp tenant_id = app_url = https://app.flightschedulepro.com timeout = 10 +use_working_dir_for_tmp = false [firefox] diff --git a/save_progress_reports.py b/save_progress_reports.py index 5b13421..614123d 100644 --- a/save_progress_reports.py +++ b/save_progress_reports.py @@ -1,5 +1,6 @@ from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait +from selenium.common.exceptions import TimeoutException from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.webdriver.common.print_page_options import PrintOptions @@ -45,6 +46,10 @@ config.read(args.config) working_dir = config['main'].get('working_directory', DEFAULT_WORKING_DIRECTORY) app_url = config['main'].get('app_url', DEFAULT_APP_URL) timeout = config['main'].get('timeout', DEFAULT_TIMEOUT) +tenant_id = config['main'].get('tenant_id') +if tenant_id is None or tenant_id == "": + print('No Tenant ID configured!') + sys.exit(1) try: os.makedirs(working_dir) @@ -56,7 +61,8 @@ except OSError as exception: os.remove(f) # HACK maybe Ubuntu specific -os.environ["TMPDIR"] = working_dir +if config['main'].getboolean('use_working_dir_for_tmp', False): + os.environ["TMPDIR"] = working_dir driver_type = config['main']['driver'] # TODO only firefox for now @@ -79,10 +85,10 @@ else: def die(message=None): if message is not None: print(message) - driver.close() + driver.quit() sys.exit(0) -login_url = app_url + '/Account/Login?company='+ config['main']['tenant_id'] +login_url = app_url + '/Account/Login?company='+ tenant_id driver.get(login_url) # wait for stupid cookie modal to load and accept all ¯\_(ツ)_/¯ @@ -101,18 +107,30 @@ username = driver.find_element(By.ID, 'username') username.send_keys(config['main']['username']) username.submit() -WebDriverWait(driver, timeout).until( - EC.presence_of_all_elements_located((By.ID, 'password')) -) +try: + WebDriverWait(driver, timeout).until( + EC.presence_of_all_elements_located((By.ID, 'password')) + ) +except TimeoutException: + if len(driver.find_elements(By.XPATH, '//div[@id="alerts"]')) > 0: + die('Bad username') + die('unknown authentication error') + password = driver.find_element(By.ID, 'password') password.send_keys(config['main']['password']) password.submit() # Wait for app to load and naviagte to students "page" -WebDriverWait(driver, timeout).until( - EC.presence_of_all_elements_located((By.CLASS_NAME, 'fsp-main-drawer-content')) -) +try: + WebDriverWait(driver, timeout).until( + EC.presence_of_all_elements_located((By.CLASS_NAME, 'fsp-main-drawer-content')) + ) +except TimeoutException: + if len(driver.find_elements(By.XPATH, '//div[@id="alerts"]')) > 0: + die('Bad password') + die('unknown authentication error') + def get_student_rows(): driver.get(app_url + '/App/Students') WebDriverWait(driver, timeout).until(