from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import time from selenium.webdriver.support.select import Select import RestAPIClient import DiskUtils ## https://sullygnome.com/channel/kaicenat/365/games" def download(url): print(f"launch -> SullyGnomeRobot -> download() -> {url}") driver = webdriver.Firefox() driver.get(url) ########################################## print("stage / start / tblControl_length check") try: dataset_drop_down_element = WebDriverWait(driver, 5).until( EC.presence_of_element_located((By.NAME, "tblControl_length")) ) dataset_drop_down_element = Select(dataset_drop_down_element) dataset_drop_down_element.select_by_visible_text("100") except Exception as e: print(f"Element with class name 'tblControl_length' not found: {e}") RestAPIClient.addDownloadFailure(url) driver.quit() return False print("stage / complete / tblControl_length check") ########################################## print("stage / start / TableExportLinkButton check") try: WebDriverWait(driver, 5).until( EC.presence_of_element_located((By.CLASS_NAME, "TableExportLinkButton")) ) link = driver.find_element(By.CLASS_NAME, "TableExportLinkButton") link.click() except Exception as e: print(f"Element with class name 'TableExportLinkButton' not found: {e}") RestAPIClient.addDownloadFailure(url) driver.quit() return False print("stage / complete / TableExportLinkButton check") ########################################## print("file download started. now checking if exist before closing") while True: print("checking is file exists... [loop]") existsAlready = DiskUtils.check_download_exists_matching_url(url) print("file already exists / ",existsAlready) if existsAlready: print(f"The file matching the url '{url}' exists.") print("sleeping for 4 secs before shutting down robot") time.sleep(4) print("shutting down the robot") driver.quit() print("robot shut down. breaking. and dying.") break else: print(f"The file matching the url '{url}' DOES NOT exist.") print("sleeping for some time before checking again..."); time.sleep(1) print(" file is finished downloading.moving on.") ########################################## RestAPIClient.addDownloadSuccess(url) print("stage / complete / database updated w/ success") print(f"complete -> SullyGnomeRobot -> download() -> {url}")