Added input handeling system in case someone actually wants to use this...

main
Graham Helton 3 years ago
parent c243961df5
commit d5170fd4b7

@ -18,6 +18,8 @@ count = 0
options = FirefoxOptions() options = FirefoxOptions()
nameList = [] nameList = []
priceList = [] priceList = []
reset = Style.RESET_ALL
tick = Fore.BLUE + "[" + Fore.GREEN + "+" + Fore.BLUE + "]" + reset
print(Fore.GREEN + print(Fore.GREEN +
''' '''
@ -33,7 +35,7 @@ print(Fore.GREEN +
/ \___________/ \\ / \___________/ \\
\_____________________/ \_____________________/
--- H A P P Y S N A K E --- --- H A P P Y S N A K E ---
''' + Style.RESET_ALL ''' + reset
) )
def goToParent(): def goToParent():
driver.switch_to.parent_frame(); driver.switch_to.parent_frame();
@ -45,8 +47,7 @@ driver = webdriver.Firefox(options=options)
driver.get("https://happymugcoffee.com/collections/roasted-coffee") driver.get("https://happymugcoffee.com/collections/roasted-coffee")
# List the coffee names on the site # List the coffee names on the site
print(Fore.BLUE + "[+]" + " Which coffee would you like? ") print(tick + " Which coffee would you like? " + reset)
print(Style.RESET_ALL)
blends = driver.find_element_by_id("Collection") blends = driver.find_element_by_id("Collection")
#print(blends.text) #print(blends.text)
blendName = driver.find_elements_by_class_name("visually-hidden") blendName = driver.find_elements_by_class_name("visually-hidden")
@ -75,19 +76,18 @@ for i in nameFixed:
dic[count]=i dic[count]=i
for key, value in dic.items(): for key, value in dic.items():
print(key, ' : ', value) print(key, ' : ', value)
selection = input(Fore.BLUE+ "[+]" + " Type the number of the coffee you would like\n" + Style.RESET_ALL) selection = input(tick + Fore.BLUE + " Type the number of the coffee you would like\n" + reset)
# Lookup the key/value in dictionary then click the correct coffee # Lookup the key/value in dictionary then click the correct coffee
value = dic[int(selection)] value = dic[int(selection)]
print(Fore.BLUE + "[+]" + " Selecting " + value + "...") print(tick + Fore.BLUE + " Selecting " + value + "...")
driver.find_element_by_link_text(value).click() driver.find_element_by_link_text(value).click()
cart = driver.find_elements_by_id("AddToCart-product-template")[0] cart = driver.find_elements_by_id("AddToCart-product-template")[0]
cart.click() cart.click()
driver.find_element_by_xpath("/html/body/div[4]/main/div/div/form/div/div/div[2]/div[4]/input[2]").click() driver.find_element_by_xpath("/html/body/div[4]/main/div/div/form/div/div/div[2]/div[4]/input[2]").click()
# Input shipping info (Condense into for loop later) # Input shipping info (Condense into for loop later)
print(Fore.BLUE + "[+]" + " Adding info from " + Fore.GREEN + "config.json" + Fore.BLUE + "...") print(tick + Fore.BLUE + " Adding info from " + Fore.GREEN + "config.json" + Fore.BLUE + "..." + reset)
print(Style.RESET_ALL)
time.sleep(2) time.sleep(2)
send = driver.find_element_by_id("checkout_email") send = driver.find_element_by_id("checkout_email")
send.send_keys(data["email"]) send.send_keys(data["email"])
@ -139,9 +139,15 @@ driver.find_element_by_id("verification_value").send_keys(data["cvc"])
# Press pay # Press pay
goToParent() goToParent()
total = driver.find_element_by_xpath("/html/body/div/div/aside/div[2]/div[1]/div/div[3]/table/tfoot/tr/td/span[2]").text total = driver.find_element_by_xpath("/html/body/div/div/aside/div[2]/div[1]/div/div[3]/table/tfoot/tr/td/span[2]").text
Pay = input(Fore.BLUE + "Your total is: " + Fore.GREEN + total + Fore.RED+ "\nSubmit order? Yes/No: " ) pay = input(tick + Fore.BLUE + "Your total is: " + Fore.GREEN + total + Fore.RED+ "\nSubmit order? Yes/No: " + reset)
# Pay now # Pay now
# UNCOMMENT THIS WITH CARE, IT WILL PROCESS YOUR ORDER if "y" in pay:
#driver.find_element_by_id('continue_button').click() print(tick + Fore.GREEN + "Processing transaction... (this will take 10 seconds)")
time.sleep(10)
#driver.close() print(tick + Fore.GREEN + "Your coffee has been bought!")
#UNCOMMENT THIS WITH CARE, IT WILL PROCESS YOUR ORDER
#driver.find_element_by_id('continue_button').click()
else:
print(Fore.RED + "Exiting without buying!")
driver.close()

Loading…
Cancel
Save