Michael Tang пре 4 година
родитељ
комит
606d71fc3c
7 измењених фајлова са 111 додато и 2 уклоњено
  1. 43 0
      401.py
  2. 21 0
      \
  3. BIN
      chromedriver
  4. BIN
      google-chrome-stable_current_amd64.deb
  5. 2 2
      newegg.py
  6. 32 0
      session.py
  7. 13 0
      test.py

+ 43 - 0
401.py

@@ -0,0 +1,43 @@
+import time
+from selenium import webdriver
+
+DRIVER_PATH = "/home/michtang/selenium/chromedriver"
+# Shining Fates ETB
+URL  = "https://store.401games.ca/collections/pokemon-shining-fates-pre-orders/products/pokemon-shiningfates-elitetrainerboxpre-order"
+# Board Game Test
+# URL = "https://store.401games.ca/collections/pokemon-sealed-product/products/pokemon-battleacademyboxset"
+driver = webdriver.Chrome(DRIVER_PATH)
+driver.get(URL)
+time.sleep(3)
+found = 0
+timeWait = 100
+buttons = driver.find_elements_by_id("AddToCart-product-template")
+while found == 0:
+    if buttons[0].get_attribute("innerText") == "SOLD OUT":
+        print(buttons[0].text)
+        while timeWait > 0:
+            print("waiting to refesh in " + str(timeWait) )
+            timeWait = timeWait - 1
+            time.sleep(1)
+        print("Time to refresh")
+        driver.refresh()
+        buttons = driver.find_elements_by_id("AddToCart-product-template")
+        timeWait = 100
+    else:
+        found = 1
+        print(buttons[0].text)
+        quantity = driver.find_element_by_id("Quantity")
+        quantity.clear()
+        quantity.send_keys("10")
+        buttons = driver.find_elements_by_id("AddToCart-product-template")
+        buttons[0].click()
+        time.sleep(3)
+        cart = driver.find_elements_by_id("CartButton")
+        cart[0].click()
+        checkout = driver.find_element_by_xpath("//input[@name='checkout']")
+        checkout.click()
+        time.sleep(1)
+        email = driver.find_element_by_xpath("//input[@name='customer[email]']")
+        email.send_keys("michael.h.tang@gmail.com")
+        password = driver.find_element_by_xpath("//input[@name='customer[password]']")
+        print("done")

+ 21 - 0
\

@@ -0,0 +1,21 @@
+Add automated click of submit button to checkIn()
+
+Signed-off-by: Michael Tang <michael.h.tang@gmail.com>
+
+# Please enter the commit message for your changes. Lines starting
+# with '#' will be ignored, and an empty message aborts the commit.
+#
+# On branch master
+# Your branch is up to date with 'origin/master'.
+#
+# Changes to be committed:
+#	modified:   session.py
+#
+# Changes not staged for commit:
+#	modified:   newegg.py
+#
+# Untracked files:
+#	chromedriver
+#	google-chrome-stable_current_amd64.deb
+#	test.py
+#


BIN
google-chrome-stable_current_amd64.deb


+ 2 - 2
newegg.py

@@ -1,7 +1,7 @@
 import time
 from selenium import webdriver
 
-DRIVER_PATH = "/Users/michaeltang/.wdm/drivers/chromedriver/88.0.4324.96/mac64/chromedriver"
+DRIVER_PATH = "/home/michtang/selenium/chromedriver"
 URL  = "https://www.newegg.ca/zotac-geforce-rtx-3080-zt-a30800d-10p/p/N82E16814500502"
 # URL = "https://www.newegg.ca/samsung-860-evo-series-500gb/p/N82E16820147674?Item=N82E16820147674&cm_sp=Homepage_dailydeals-_-P0_20-147-674-_-02032021"
 driver = webdriver.Chrome(DRIVER_PATH)
@@ -10,7 +10,7 @@ time.sleep(3)
 found = 0
 timeWait = 100
 buttons = driver.find_elements_by_class_name("btn")
-popup = driver.find_element_by_id("popup-close")
+# popup = driver.find_element_by_id("popup-close")
 while found == 0:
     if buttons[0].get_attribute("innerText") == "OUT OF STOCK":
         print("OUT OF STOCK")

+ 32 - 0
session.py

@@ -58,6 +58,9 @@ def checkIn():
     if pressSubmit == "y":
         print(buttons[1].text)
         buttons[1].click()
+        time.sleep(1)
+        print("quitting")
+        driver.quit()
     elif pressSubmit == "n":
         print("Manual mode")
         buttons[0].click()
@@ -80,15 +83,44 @@ def checkOut():
 
     whoWereYouHereFor = driver.find_element_by_css_selector(".exportTextarea")
     whoWereYouHereFor.send_keys(whoHereFor)
+
+    # Automated click of submit
+    buttons =  driver.find_elements_by_class_name("quantumWizButtonPaperbuttonLabel")
+    # find the submit button 
+    buttonText = buttons[1].text
+    pressSubmit = input("Press submit? (y/n)")
+    if pressSubmit == "y":
+        print(buttons[1].text)
+        buttons[1].click()
+        time.sleep(1)
+        print("quitting")
+        driver.quit()
+    elif pressSubmit == "n":
+        print("Manual mode")
+        buttons[0].click()
+    else:
+        print("invalid key pressed.")
     ############################ end Check Out ##############################
 
 def locationSelector():
     print("Select the school: ")
     print("1. ABM")
+    print("2. DTK")
+    print("3. LOHS")
+    print("4. GHL")
+    print("5. DDM")
     schoolSelected = input("Select the school: ")
     if schoolSelected == "1":
         global URL
         URL = "https://docs.google.com/forms/d/e/1FAIpQLSeJf3A_bADAUyaXuTEfiyU5O4V77PxcL9lYBSC3vgP4Fn4eGg/viewform"
+    elif schoolSelected == "2":
+        URL = "https://docs.google.com/forms/d/e/1FAIpQLSfIZdJoeB8MUrUSAsbKkgsrsRbXB0nUYui2Dn2weCfa5l_KIw/viewform"
+    elif schoolSelected == "3":
+        URL = "https://docs.google.com/forms/d/e/1FAIpQLSeACzhxKn6mVV0ArePRXE1qz_uojT9CT53OaXnYpEh7T4GzJg/viewform"
+    elif schoolSelected == "4":
+        URL = "https://docs.google.com/forms/d/e/1FAIpQLSdIT2XbkW4leXrQmS0rEuQ70lZoXkNG_zv7a0JOIRS4wuyxfw/viewform"
+    elif schoolSelected == "5":
+        URL = "https://docs.google.com/forms/d/e/1FAIpQLSeQJO4uzCHg-OIawaWiVcjJrhcVsFKZ-2hDF4wOaDmz9Xx86w/viewform"
     else:
         print("not a valid selection.")
         locationSelector()

+ 13 - 0
test.py

@@ -0,0 +1,13 @@
+import sys
+from selenium import webdriver
+from selenium.webdriver.common.keys import Keys
+import random
+from time import sleep
+
+chrome_options = webdriver.ChromeOptions()
+chrome_options.add_argument('--headless')
+chrome_options.add_argument('--no-sandbox') # required when running as root user. otherwise you would get no sandbox errors. 
+driver = webdriver.Chrome(executable_path='/home/michtang/selenium/chromedriver', options=chrome_options, service_args=['--verbose', '--log-path=/tmp/chromedriver.log'])
+
+driver.get('https://python.org') 
+print(driver.title)