Added example gif and cleaned up some code

main
Graham Helton 3 years ago
parent b1c64e186b
commit 6df685ed49

@ -1 +1,10 @@
# happysnake
# What is this?
HappySnake is a tool I created to quickly order coffee from https://www.happymugcoffee.com. I mostly made this to help me learn python so don't expect it to be effecient (or even a very good idea... It's probably not wise to buy things using a script unless you really know what you're doing but oh well.)
# Requirements
'''bash
pip3 install selenium colorama
'''
# Usage
To run simple create a file called config.json in the directory above where you installed the tool (Please don't put a config.json in a git directory...). I recommend not testing with real info until you're sure this behaves how you expect it to.
![](example.gif)

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 MiB

@ -10,13 +10,14 @@ import time
#Initialize variables and get config
with open('../config.json') as configFile:
data=json.load(configFile)
testing = data["cardNumber"]
testingExpo = data["expo"]
cardData = data["cardNumber"]
expoData = data["expo"]
dic = {}
count = 0
options = FirefoxOptions()
nameList = []
priceList = []
print(Fore.GREEN +
'''
( ) ( ) )
@ -36,7 +37,6 @@ print(Fore.GREEN +
def goToParent():
driver.switch_to.parent_frame();
#options.add_argument("--headless")
driver = webdriver.Firefox(options=options)
driver.get("https://happymugcoffee.com/collections/roasted-coffee")
@ -70,22 +70,19 @@ nameFixed.remove("Coffee Subscription - Roaster's Choice B")
for i in nameFixed:
count+=1
dic[count]=i
for key, value in dic.items():
print(key, ' : ', value)
selection = input(Fore.BLUE+ "[+]" + " Type the number of the coffee you would like\n" + Style.RESET_ALL)
#print(Style.RESET_ALL)
# Lookup the key/value in dictionary then click the correct coffee
value = dic[int(selection)]
print(Fore.BLUE + "[+]" + " Selecting " + value + "...")
driver.find_element_by_link_text(value).click()
cart = driver.find_elements_by_id("AddToCart-product-template")[0]
cart.click()
driver.find_element_by_xpath("/html/body/div[4]/main/div/div/form/div/div/div[2]/div[4]/input[2]").click()
# Input shopping 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(Style.RESET_ALL)
time.sleep(2)
@ -104,22 +101,22 @@ send.send_keys(data["city"])
send = driver.find_element_by_id("checkout_shipping_address_zip")
send.send_keys(data["zip"])
#Continue to shipping
#Continue to shipping and wait for load
driver.find_element_by_id("continue_button").click()
time.sleep(2)
driver.find_element_by_id("continue_button").click()
# Input Card Details
time.sleep(2)
#Switch to iframe
#Switch to iframe and add card data
iframe = driver.find_element_by_xpath("//iframe[@class='card-fields-iframe']")
driver.switch_to.frame(iframe)
send = driver.find_element_by_xpath("//*[@id='number']")
# Add numbers one by one becuase it doesn't like when you add it all at once
for i in range (0,len(testing)):
send.send_keys(testing[i])
for i in range (0,len(cardData)):
send.send_keys(cardData[i])
# Input First and last name
# Input firstName and firstName
goToParent()
driver.switch_to.frame(driver.find_element_by_xpath("//*[contains(@id, 'card-fields-name-')]"))
driver.find_element_by_id("name").send_keys(data["firstName"])
@ -128,14 +125,15 @@ driver.find_element_by_id("name").send_keys(" " + data["lastName"])
# Input expiration date
goToParent()
driver.switch_to.frame(driver.find_element_by_xpath("//*[contains(@id, 'card-fields-expiry-')]"))
for i in range(0,len(testingExpo)):
driver.find_element_by_id("expiry").send_keys(testingExpo[i])
for i in range(0,len(expoData)):
driver.find_element_by_id("expiry").send_keys(expoData[i])
# Input CVC
goToParent()
driver.switch_to.frame(driver.find_element_by_xpath("//*[contains(@id, 'card-fields-verification_value-')]"))
driver.find_element_by_id("verification_value").send_keys(data["cvc"])
# Press pay
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
Pay = input(Fore.BLUE + "Your total is: " + Fore.GREEN + total + Fore.RED+ "\nSubmit order? Yes/No: " )

Loading…
Cancel
Save