예제 #1
0
def selectMountain(driver, mountain):
    """Selects mountain on the 'make reservation' page. From here, selectMonth() 
	and then isDayAvailable() can be called.
	"""
    # select mountain
    try:
        # wait for page to load
        mountain = WebDriverWait(driver, 20).until(
            EC.presence_of_element_located(
                (By.XPATH, '//span[text()="' + mountain + '"]')))
    except:
        print("Error: Timed out")
        emailInterface.sendErrorEmail("Error selecting mountain " + mountain,
                                      ikonEmail)
        sys.exit()
    driver.execute_script("arguments[0].click();", mountain)

    # click 'Continue' button
    try:
        # wait for page to load
        contButton = WebDriverWait(driver, 20).until(
            EC.presence_of_element_located(
                (By.XPATH, '//span[text()="Continue"]')))
    except:
        print("Error: Timed out")
        emailInterface.sendErrorEmail("Error selecting mountain " + mountain,
                                      ikonEmail)
        sys.exit()
    driver.execute_script("arguments[0].click();", contButton)
예제 #2
0
def login(driver):
    """Logs into Ikon website and clicks the 'make reservation' button.
	"""
    # open login page
    url = "https://account.ikonpass.com/en/login"
    driver.get(url)

    # send login parameters
    username = driver.find_element_by_name('email')
    username.send_keys(ikonEmail)
    password = driver.find_element_by_name('password')
    password.send_keys(ikonPassword)
    password.send_keys(Keys.RETURN)

    # click 'Make a Reservation' button
    try:
        # wait for page to load
        resButton = WebDriverWait(driver, 20).until(
            EC.presence_of_element_located(
                (By.XPATH, '//span[text()="Make a Reservation"]')))
    except:
        print("Error: Timed out")
        emailInterface.sendErrorEmail("Error logging in", ikonEmail)
        sys.exit()
    driver.execute_script("arguments[0].click();", resButton)
예제 #3
0
def isDayAvailable(driver, month, day, year):
    """Checks if a day is available. The scraper must be on the make reservation
	page with the dates available to check (ie selectMonth() must be called first).
	"""
    # parse monthInput since that is how it is labeled in the Ikon page HTML
    month = month[0:3]

    # format day, if it's single digits, prepend with 0 since that is Ikon's
    # site format
    dayFormatted = str(day)
    if (day < 10):
        dayFormatted = "0" + dayFormatted

    # check if day is available by reading element class. Class will be
    # 'DayPicker-Day' if available
    try:
        # wait for page to load
        dayElement = WebDriverWait(driver, 20).until(
            EC.presence_of_element_located(
                (By.XPATH, '//div[contains(@aria-label,"' + str(month) + ' ' +
                 dayFormatted + '")]')))
    except:
        print("Error: Timed out")
        emailInterface.sendErrorEmail(
            "Error checking day availability for " + str(month) + " " +
            str(day), ikonEmail)
        sys.exit()

    # return if day is available or not
    if (dayElement.get_attribute('class') == AVAILABLE
            or dayElement.get_attribute('class') == AVAILABLE_TODAY):
        return True
    else:
        return False
예제 #4
0
def login(driver):
    """Logs into Ikon website and clicks the 'make reservation' button.
	"""
    # open login page
    url = "https://account.ikonpass.com/en/login"
    driver.get(url)

    # If Ikon is using captcha, attempt to run the script 5+ times, then they
    # will ask for captcha right when bot gets to site. Uncomment this timer
    # and manually enter captcha, then bot will run after. Make sure headless
    # mode is off
    #time.sleep(120)

    # send login parameters
    username = driver.find_element_by_name('email')
    username.send_keys(ikonEmail)
    password = driver.find_element_by_name('password')
    password.send_keys(ikonPassword)
    password.send_keys(Keys.RETURN)

    # click 'Make a Reservation' button
    try:
        # wait for page to load
        resButton = WebDriverWait(driver, 20).until(
            EC.presence_of_element_located(
                (By.XPATH, '//span[text()="Make a Reservation"]')))
    except:
        print("Error: Timed out")
        emailInterface.sendErrorEmail("Error logging in", ikonEmail)
        sys.exit()
    driver.execute_script("arguments[0].click();", resButton)
예제 #5
0
def selectMonth(driver, month, year):
    """Selects month by bringing scraper to the page displaying the dates for that
	month.
	"""
    # check what month is currently being checked on Ikon site.
    try:
        # wait for page to load
        monthBeingChecked = WebDriverWait(driver, 20).until(
            EC.presence_of_element_located(
                (By.XPATH, '//span[@class="sc-qPyvj jTgFdL"]')))
    except:
        print("Error: Timed out")
        emailInterface.sendErrorEmail("Error selecting month " + str(month),
                                      ikonEmail)
        sys.exit()

    # loop through months until correct month is being checked.
    # Will start from month entered and increment until June 2021.
    while (monthBeingChecked.get_attribute('innerHTML') !=
           (month + ' ' + str(year))):
        # if we have reached June and that was not desired month, return
        if monthBeingChecked.get_attribute('innerHTML') == (
                "June 2021") and month != "June":
            print("Error: Failed to select month")
            return

        # go to next month
        nextMonthButton = driver.find_element(
            By.XPATH, '//i[@class="amp-icon icon-chevron-right"]')
        driver.execute_script("arguments[0].click();", nextMonthButton)

        try:
            monthBeingChecked = WebDriverWait(driver, 20).until(
                EC.presence_of_element_located(
                    (By.XPATH, '//span[@class="sc-qPyvj jTgFdL"]')))
        except:
            print("Error: Timed out")
            emailInterface.sendErrorEmail(
                "Error selecting month " + str(month), ikonEmail)
            sys.exit()
예제 #6
0
def reserveDay(driver, month, day, year, mountain):
    """Reserves a day in Ikon if available.
	"""
    # parse monthInput since that is how it is labeled in the Ikon page HTML
    month = month[0:3]

    # format day, if it's single digits, prepend with 0 since that is Ikon's
    # site format
    dayFormatted = str(day)
    if (day < 10):
        dayFormatted = "0" + dayFormatted

    # Select the day
    # if available
    try:
        # wait for page to load
        dayElement = WebDriverWait(driver, 20).until(
            EC.presence_of_element_located(
                (By.XPATH, '//div[contains(@aria-label,"' + str(month) + ' ' +
                 dayFormatted + '")]')))
        driver.execute_script("arguments[0].click();", dayElement)
    except:
        emailInterface.sendErrorEmail(
            "Error reserving " + mountain + " on " + str(month) + " " +
            str(day) + ", " + str(year), ikonEmail)
        return 0

    # click save button
    try:
        # wait for page to load
        saveButton = WebDriverWait(driver, 20).until(
            EC.presence_of_element_located(
                (By.XPATH, '//span[text()="Save"]')))
        driver.execute_script("arguments[0].click();", saveButton)
    except:
        emailInterface.sendErrorEmail(
            "Error reserving " + mountain + " on " + str(month) + " " +
            str(day) + ", " + str(year), ikonEmail)
        return 0

    # give time for button click
    time.sleep(1)

    # click confirm button
    try:
        # wait for page to load
        confirmButton = WebDriverWait(driver, 20).until(
            EC.presence_of_element_located(
                (By.XPATH, '//span[text()="Continue to Confirm"]')))
        driver.execute_script("arguments[0].click();", confirmButton)
    except:
        emailInterface.sendErrorEmail(
            "Error reserving " + mountain + " on " + str(month) + " " +
            str(day) + ", " + str(year), ikonEmail)
        return 0

    # give time for button click
    time.sleep(1)

    # click confirm checkbox
    try:
        # wait for page to load
        confirmCheckbox = WebDriverWait(driver, 20).until(
            EC.presence_of_element_located((
                By.XPATH,
                '//*[@id="root"]/div/div/main/section[2]/div/div[2]/div[4]/div/div[4]/label/input'
            )))
        driver.execute_script("arguments[0].click();", confirmCheckbox)
    except:
        emailInterface.sendErrorEmail(
            "Error reserving " + mountain + " on " + str(month) + " " +
            str(day) + ", " + str(year), ikonEmail)
        return 0

    # give time for button click
    time.sleep(1)

    # click confirm button again
    try:
        # wait for page to load
        confirmButton = WebDriverWait(driver, 20).until(
            EC.presence_of_element_located((
                By.XPATH,
                '//*[@id="root"]/div/div/main/section[2]/div/div[2]/div[4]/div/div[5]/button/span'
            )))
        driver.execute_script("arguments[0].click();", confirmButton)
    except:
        emailInterface.sendErrorEmail(
            "Error reserving " + mountain + " on " + str(month) + " " +
            str(day) + ", " + str(year), ikonEmail)
        return 0

    return 1