fangraphs_db.py
def download_leaderboard(link):
    """Download the leaderboard and return a bool if successful."""
    # Clear any existing file
    clear_temp()

    # Specify the driver
    driver = specify_driver()

    # Wait a reasonable time that a person would take
    wait = WebDriverWait(driver, 20)

    # Instruct the browser to go to the correct page
    driver.get(link)

    # Wait until the element to download is available and then stop loading
    # Fangraphs has ads that cause the page to appear to continue loading
    wait.until(EC.presence_of_element_located((By.ID, "LeaderBoard1_cmdCSV")))
    driver.execute_script("window.stop();")

    # Click the Export Data button
    # Scrolling down the page helps get to the file more reliably
    driver.execute_script("window.scrollTo(0, 200)")
    driver.find_element_by_id("LeaderBoard1_cmdCSV").click()

    leaderboard = Path('data') / 'Fangraphs Leaderboard.csv'

    # Wait up to one minute for the file to download
    exists = False
    for _ in range(0, 600):
        if leaderboard.is_file():
            exists = True
            break
        else:
            time.sleep(10)

    # Close the selenium window
    driver.close()

    return exists
Download the leaderboard and return a bool if successful.
Download the leaderboard and return a bool if successful.
Download the leaderboard and return a bool if successful .
def download_leaderboard(link):
    clear_temp()
    driver = specify_driver()
    wait = WebDriverWait(driver, 20)
    driver.get(link)
    wait.until(EC.presence_of_element_located((By.ID, "LeaderBoard1_cmdCSV")))
    driver.execute_script("window.stop();")
    driver.execute_script("window.scrollTo(0, 200)")
    driver.find_element_by_id("LeaderBoard1_cmdCSV").click()
    leaderboard = Path('data') / 'Fangraphs Leaderboard.csv'
    exists = False
    for _ in range(0, 600):
        if leaderboard.is_file():
            exists = True
            break
        else:
            time.sleep(10)
    driver.close()
    return exists
def download_leaderboard ( link ) : clear_temp ( ) driver = specify_driver ( ) wait = WebDriverWait ( driver , 20 ) driver . get ( link ) wait . until ( EC . presence_of_element_located ( ( By . ID , "LeaderBoard1_cmdCSV" ) ) ) driver . execute_script ( "window.stop();" ) driver . execute_script ( "window.scrollTo(0, 200)" ) driver . find_element_by_id ( "LeaderBoard1_cmdCSV" ) . click ( ) leaderboard = Path ( 'data' ) / 'Fangraphs Leaderboard.csv' exists = False for _ in range ( 0 , 600 ) : if leaderboard . is_file ( ) : exists = True break else : time . sleep ( 10 ) driver . close ( ) return exists
Download the leaderboard and return a bool if successful.
Download the leaderboard and return a bool if successful .
"""Download the leaderboard and return a bool if successful.""" # Clear any existing file
 # Specify the driver
 # Wait a reasonable time that a person would take
 # Instruct the browser to go to the correct page
 # Wait until the element to download is available and then stop loading
 # Fangraphs has ads that cause the page to appear to continue loading
 # Click the Export Data button
 # Scrolling down the page helps get to the file more reliably
 # Wait up to one minute for the file to download
 # Close the selenium window

link