Guest User

FESBSC #1

a guest
Dec 6th, 2017
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.58 KB | None | 0 0
  1. import time
  2. import os.path
  3. import openpyxl
  4.  
  5. from selenium.webdriver.chrome.options import Options
  6. from selenium.common.exceptions import NoSuchElementException
  7. from selenium.webdriver.support.ui import WebDriverWait
  8. from selenium import webdriver
  9. from openpyxl import Workbook
  10. import win32ui, win32gui
  11. import selenium.webdriver.chrome.service as service
  12. from selenium.webdriver.common.keys import Keys
  13. from selenium.webdriver.common.by import By
  14. from selenium import webdriver
  15. from selenium.webdriver.chrome.options import Options
  16. from selenium.webdriver.support.ui import WebDriverWait
  17. from selenium.webdriver.support import expected_conditions as EC
  18. from selenium.webdriver.support.ui import Select
  19. import win32com.client as comclt
  20. import datetime
  21. import re
  22. import sys
  23. from datetime import datetime
  24. import pytz
  25.  
  26. wsh = comclt.Dispatch("WScript.Shell")
  27.  
  28. categoryList = []
  29. categoryList.append("jackets")
  30. categoryList.append("shirts")
  31. categoryList.append("tops/sweaters")
  32. categoryList.append("sweatshirts")
  33. categoryList.append("pants")
  34. categoryList.append("hats")
  35. categoryList.append("bags")
  36. categoryList.append("accessories")
  37. categoryList.append("shoes")
  38. categoryList.append("skate")
  39.  
  40. def readPath():
  41.     f = open("chromepath.txt", "r").readlines()
  42.     makeitastring = ''.join(map(str, f))
  43. chromePath = readPath()
  44.  
  45. service = service.Service('chromedriver.exe')
  46. capabilities = {'chrome.binary': chromePath}
  47.  
  48. def checkIfCategory():
  49.     categoryInput = input("Select type: jackets, shirts, tops/sweaters, sweatshirts, pants, hats, bags, accessories, shoes, skate \n")
  50.     selected = "nothing"
  51.     for category in categoryList:
  52.         if categoryInput == category:
  53.             selected = category
  54.     if selected == "nothing":
  55.         print("Please enter one of the listed categories exactly")
  56.         return checkIfCategory()
  57.     elif selected != "nothing":
  58.         string = "Selected Category: "
  59.         string += selected
  60.         print(string)
  61.         return selected
  62.        
  63. keywords = []
  64.  
  65. def selectKeywords():
  66.     keywordsInput = input("Select keywords, use a comma to separate tags and don't use any spaces e.g. Reflective,Sleeve,Logo,Puffer \n")
  67.     split = keywordsInput.strip().split(",")
  68.     for splits in split:
  69.         keywords.append(splits)
  70.  
  71. sizeC = 0
  72.  
  73. def selectSize():
  74.     print("Select Size (Alternatively simply enter 'D' for the first available size)")
  75.     if selectedCategory == "jackets" or selectedCategory == "shirts" or selectedCategory == "tops/sweaters" or selectedCategory == "sweatshirts":
  76.         string = "Possible Sizes for "
  77.         string += selectedCategory
  78.         string += ": Small, Medium, Large, XLarge"
  79.         print(string)
  80.         sizeInput = input("Select size: ")
  81.         if sizeInput == "Small" or sizeInput == "Medium" or sizeInput == "Large" or sizeInput == "XLarge":
  82.             print("Success")
  83.             return sizeInput
  84.         elif sizeInput != "Small" or sizeInput != "Medium" or sizeInput != "Large" or sizeInput != "XLarge":
  85.             print("Please enter one of the listed sizes exactly")
  86.             print(sizeInput)
  87.             return selectSize()
  88.        
  89.         print(string)
  90.     else:
  91.         sizeInput = input("Select size: ")
  92.         if sizeInput == "D":
  93.             sizeC = 1
  94.         elif sizeInput != "D":
  95.             siceC = 2
  96.         return sizeInput
  97.  
  98. def selectColour():
  99.     colour = input("Select a colour/model (please use a capital letter e.g. Black/Red/Blue) ")
  100.     text = "Selected colour: "
  101.     text += colour
  102.     answer = input("Is this the colour you want to select? (Y/N) ")
  103.     if answer == "Y":
  104.         print(text)
  105.         return colour
  106.     elif answer == "N":
  107.         return selectColour()
  108.  
  109. def listOptions():
  110.     print("-------------------------------------")
  111.     category = "Selected Category: "
  112.     category += selectedCategory
  113.     print(category)
  114.     print("Selected Keywords: ")
  115.     print(keywords)
  116.     print("Selected Size: ")
  117.     print(selectedSize)
  118.     colour = "Selected Colour: "
  119.     colour += selectedColour
  120.     print(colour)
  121.     print("Please make sure all of these values are correct. If they are not please restart the program and try again.")
  122.     print("If you have any questions please view the respective reddit post or email me at shaerthomas@gmail.com")
  123.     print("-------------------------------------\n")
  124.  
  125. checkedListings = []
  126.  
  127. def selectName():
  128.     name = input("Enter Name: ")
  129.     return name
  130.  
  131. def selectEmail():
  132.     email = input("Enter Email: ")
  133.     return email
  134.  
  135. def selectPhone():
  136.     phone = input("Enter Phone Number: ")
  137.     return phone
  138.  
  139. def selectAdd1():
  140.     add1 = input("Enter Address 1: ")
  141.     return add1
  142.  
  143. def selectAdd2():
  144.     add2 = input("Enter Address 2: ")
  145.     return add2
  146.  
  147. def selectAdd3():
  148.     add3 = input("Enter Address 3: ")
  149.     return add3
  150.  
  151. def selectCity():
  152.     city = input("Enter City: ")
  153.     return city
  154.  
  155. def selectPostcode():
  156.     postcode = input("Enter Postcode: ")
  157.     return postcode
  158.  
  159. def selectCardno():
  160.     cardno = input("Enter Card Number: ")
  161.     return cardno
  162.  
  163. def selectCardx():
  164.     cardX = input("Enter Card CVV: ")
  165.     return cardX
  166.  
  167. def selectCardx1():
  168.     cardX1 = input("Enter Card Month Expire Date (e.g. 05 for may): ")
  169.     return cardX1
  170.  
  171. def selectCardx2():
  172.     cardX2 = input("Enter Card Month Expire Year: ")
  173.     return cardX2
  174. cardType1 = 0
  175.  
  176. def selectCardType():
  177.     cardX2 = input("Enter Payment Type (e.g. Solo, Visa, PayPal): ")
  178.     if cardX2 == "PayPal":
  179.         cardType1 = 1
  180.     return cardX2
  181.  
  182. def check_exists_by_xpath(xpath, driver):
  183.     try:
  184.         myElem = WebDriverWait(driver, 1).until(EC.presence_of_element_located((By.XPATH, xpath)))
  185.         return driver.find_element_by_xpath(xpath)
  186.     except NoSuchElementException:
  187.         myElem = WebDriverWait(driver, 1).until(EC.presence_of_element_located((By.XPATH, xpath)))
  188.         return driver.find_element_by_xpath(xpath)
  189.     return True
  190.  
  191. def returnTime():
  192.     timeS = "Please enter the hour of the drop (e.g. if you're in the UK enter '11' for 11.00am) "
  193.        
  194.     isTime = input(timeS)
  195.     dropTime = int(isTime)
  196.     text = "Drop selected for "
  197.     text += isTime
  198.     text += ":00"
  199.     text += " the program will automatically run at this time. Please do not close the web browser or cmd box."
  200.     print(text)
  201.     while True:
  202.         ts = time.time()
  203.         houra = datetime.fromtimestamp(ts).strftime('%H')
  204.         hour = int(houra)
  205.         if hour >= dropTime:
  206.             break
  207.  
  208. def openChrome():
  209.     service.start()
  210.     driver = webdriver.Remote(service.service_url, capabilities)
  211.  
  212.     returnTime()
  213.     url = 'http://www.supremenewyork.com/shop/all/'
  214.     url += selectedCategory
  215.     driver.get(url);
  216.     listings = driver.find_elements_by_class_name("name-link")
  217.     for i in range(0, len(listings), 1):
  218.         if i % 2 != 0:
  219.             text = listings[i-1].text
  220.             split = text.strip().split(" ")
  221.             matches = 0
  222.             colour = 0
  223.             for keyword in keywords:
  224.                 for splits in split:
  225.                     if keyword == splits:
  226.                         matches += 1
  227.             coloura = listings[i].text
  228.             if selectedColour == coloura:
  229.                 colour = 1
  230.             if matches != 0:
  231.                 matches += colour
  232.             checkedListings.append(matches)
  233.     largestMatch = 0
  234.     for i in range(0, len(checkedListings), 1):
  235.         if checkedListings[i] > largestMatch:
  236.             largestMatch = i
  237.             if i == 0 or i == 1:
  238.                 largestMatch = 0
  239.  
  240.     listings[largestMatch * 2].click()
  241.  
  242.     time.sleep(0.8)
  243.  
  244.     if sizeC == 1:
  245.         size = Select(driver.find_element_by_id("size"))
  246.         size.select_by_visible_text(selectedSize)
  247.  
  248.     try:
  249.         add = driver.find_element_by_xpath("""//*[@id="add-remove-buttons"]/input""")
  250.         add.click()
  251.     except NoSuchElementException:
  252.         print("Sorry the item is sold out!")
  253.         return
  254.  
  255.     time.sleep(0.5)
  256.     cart = check_exists_by_xpath("""//*[@id="cart"]/a[2]""", driver)
  257.     cart.click()
  258.  
  259.  
  260.     name = check_exists_by_xpath("""//*[@id="order_billing_name"]""", driver)
  261.     name.send_keys(selectedName)
  262.  
  263.     email = check_exists_by_xpath("""//*[@id="order_email"]""", driver)
  264.     email.send_keys(selectedEmail)
  265.  
  266.     phone = check_exists_by_xpath("""//*[@id="order_tel"]""", driver)
  267.     phone.send_keys(selectedPhone)
  268.  
  269.     add1 = check_exists_by_xpath("""//*[@id="bo"]""", driver)
  270.     add1.send_keys(selectedAdd1)
  271.  
  272.     add2 = check_exists_by_xpath("""//*[@id="oba3"]""", driver)
  273.     add2.send_keys(selectedAdd2)
  274.  
  275.     add3 = check_exists_by_xpath("""//*[@id="order_billing_address_3"]""", driver)
  276.     add3.send_keys(selectedAdd3)
  277.  
  278.     city = check_exists_by_xpath("""//*[@id="order_billing_city"]""", driver)
  279.     city.send_keys(selectedCity)
  280.  
  281.     postcode = check_exists_by_xpath("""//*[@id="order_billing_zip"]""", driver)
  282.     postcode.send_keys(selectedPostcode)
  283.     if cardType1 != 1:
  284.         cardno = check_exists_by_xpath("""//*[@id="cnb"]""", driver)
  285.         cardno.send_keys(selectedCardno)
  286.  
  287.         cvv = check_exists_by_xpath("""//*[@id="vval"]""", driver)
  288.         cvv.send_keys(selectedCardCVV)
  289.  
  290.         cardType = Select(driver.find_element_by_id("credit_card_type"))
  291.         cardType.select_by_visible_text(selectedCardType)
  292.  
  293.         expiraryDate1 = Select(driver.find_element_by_id("credit_card_month"))
  294.         expiraryDate1.select_by_visible_text(selectedCardx1)
  295.  
  296.         expiraryDate2 = Select(driver.find_element_by_id("credit_card_year"))
  297.         expiraryDate2.select_by_visible_text(selectedCardx2)
  298.  
  299.     tickBox = driver.find_element_by_xpath("""//*[@id="cart-cc"]/fieldset/p/label/div/ins""")
  300.     tickBox.click()
  301.    
  302.     complete = check_exists_by_xpath("""//*[@id="pay"]/input""", driver)
  303.     complete.click()
  304.     print("Complete the captcha and confirm the order manually. Thanks for using my bot ;)")
  305.     print("If this bot helped you make money/cop a nice item, please consider donating on paypal at shaerthomas@gmail.com!")
  306.  
  307. print("-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-")
  308. print("Thanks for using my bot. Please note this bot is experimental and in a very early development stage. \n")
  309. print("This bot is simply a script. By deciding to use this bot you are responsible for any purchases. Not me. \n")
  310. print("PLEASE ENTER THE CORRECT PATH TO YOUR CHROME.EXE IN THE 'chromepath.txt' FILE \n")
  311. print("Also note that the bot will likely cause a RECAPTCHA to appear. Please be prepared to quickly solve it and confirm the order.")
  312. print("If you have any questions please feel free to contact me at shaerthomas@gmail.com, or post on the reddit thread. \n")
  313. print("HA6")
  314. print("-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-")
  315. selectedCategory = checkIfCategory()
  316. selectKeywords()
  317. selectedSize = selectSize()
  318. selectedColour = selectColour()
  319. listOptions()
  320.  
  321. def displayDetails():
  322.     print("-------------------------------------")
  323.     print("Billing information and address.")
  324.     name = "Selected Name: "
  325.     name += selectedName
  326.     print(name)
  327.     email = "Selected Email: "
  328.     email += selectedEmail
  329.     print(email)
  330.     phone = "Selected Phone Number: "
  331.     phone += selectedPhone
  332.     print(phone)
  333.     add1 = "Selected Address 1: "
  334.     add1 += selectedAdd1
  335.     print(name)
  336.     add2 = "Selected Address 2: "
  337.     add2 += selectedAdd2
  338.     print(add2)
  339.     add3 = "Selected Address 3: "
  340.     add3 += add3
  341.     print(add3)
  342.     city = "Selected City: "
  343.     city += selectedCity
  344.     print(city)
  345.     postcode = "Selected Postcode: "
  346.     postcode += selectedPostcode
  347.     print(postcode)
  348.     cardno = "Selected Card Number: "
  349.     cardno += selectedCardno
  350.     print(cardno)
  351.     cvv = "Selected CVV: "
  352.     cvv += selectedCardCVV
  353.     print(cvv)
  354.     cardx1 = "Selected Card Expiry Month: "
  355.     cardx1 += selectedCardx1
  356.     print(cardx1)
  357.     cardx2 = "Selected Card Expiry Year: "
  358.     cardx2 += selectedCardx2
  359.     print(cardx2)
  360.     cardtype = "Selected Card Type: "
  361.     cardtype += selectedCardType
  362.     print(cardtype)
  363.     print("If any of this information is wrong please restart the program and start again.")
  364.     print("-------------------------------------")
  365.  
  366. selectedName = selectName()
  367. selectedEmail = selectEmail()
  368. selectedPhone = selectPhone()
  369. selectedAdd1 = selectAdd1()
  370. selectedAdd2 = selectAdd2()
  371. selectedAdd3 = selectAdd3()
  372. selectedCity = selectCity()
  373. selectedPostcode = selectPostcode()
  374. selectedCardno = selectCardno()
  375. selectedCardCVV = selectCardx()
  376. selectedCardx1 = selectCardx1()
  377. selectedCardx2 = selectCardx2()
  378. selectedCardType = selectCardType()
  379. displayDetails()
  380. openChrome()
Add Comment
Please, Sign In to add comment