Advertisement
Guest User

Untitled

a guest
May 3rd, 2019
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.10 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.common.keys import Keys
  3. from selenium.webdriver.common.by import By
  4. from selenium.webdriver.support.ui import WebDriverWait
  5. from selenium.webdriver.support import expected_conditions as EC
  6. from selenium.webdriver.chrome.options import Options
  7. from selenium.webdriver.common.action_chains import ActionChains
  8.  
  9. import time
  10. import random
  11. import re
  12. import threading
  13. import names
  14. import os
  15. import json
  16. import zipfile
  17. from queue import Queue
  18. import datetime
  19.  
  20.  
  21. #INSTALL PYTHON 3.6
  22. #PIP INSTALL SELENIUM
  23. #INSTALL CHROME DRIVER FOR SELENIUM
  24.  
  25. with open('config.json') as data:
  26. data = json.load(data)
  27.  
  28. ##accountlocation = data['accountlocation']
  29. ##password = data['password']
  30. ##restartprog = data['restartprog']
  31. ##useproxy = data['useproxy']
  32. ##domain = data['domain']
  33.  
  34. accountlocation = "nikeyahoo.txt"
  35. yahoolocation = "russianyahoo.txt"
  36. restartprog = True
  37. useproxy = False
  38.  
  39.  
  40. def readaccounts():
  41. accountList = []
  42. numberAccounts = 0
  43. file = open(yahoolocation,"r")
  44. for line in file:
  45. accountList.append(1)
  46. accountList[numberAccounts] = line.strip("\n")
  47. numberAccounts += 1
  48. file.close()
  49.  
  50. return accountList
  51.  
  52. def getaccount(accountList):
  53. global entirecounter
  54. full = accountList[entirecounter]
  55. split = full.split(":")
  56. email = split[0]
  57. password = split[1]
  58. password = password + "1"
  59.  
  60. return email,password
  61.  
  62.  
  63.  
  64.  
  65.  
  66. def getStartTime():
  67.  
  68. currentDT = datetime.datetime.now()
  69.  
  70. startTime = currentDT.strftime("%M:%S")
  71.  
  72. startList = list(startTime)
  73.  
  74.  
  75.  
  76. return startList
  77.  
  78. def getFinalTime(startList):
  79.  
  80. currentDT = datetime.datetime.now()
  81.  
  82. finishTime = currentDT.strftime("%M:%S")
  83.  
  84. finishList = list(finishTime)
  85.  
  86. if finishList[1] == startList[1]:
  87. startTime12 = startList[3] + startList[4]
  88. startTime = int(startTime12)
  89.  
  90. finishTime12 = finishList[3] + finishList[4]
  91. finishTime = int(finishTime12)
  92.  
  93. timeTaken = finishTime - startTime
  94. print("The time taken was " + str(timeTaken) + " seconds")
  95.  
  96. elif finishList[0] == startList[0]:
  97. startTimeMin = startList[1]
  98. startTimeMin = int(startTimeMin)
  99. startTime12 = startList[3] + startList[4]
  100. startTimeSec = int(startTime12)
  101.  
  102. finishTimeMin = finishList[1]
  103. finishTimeMin = int(finishTimeMin)
  104. finishTime12 = finishList[3] + finishList[4]
  105. finishTimeSec = int(finishTime12)
  106.  
  107. totalMin = finishTimeMin - startTimeMin
  108. totalSec = finishTimeSec - startTimeSec
  109. totalMinInSec = totalMin*60
  110. totalSec += totalMinInSec
  111.  
  112. print("here")
  113. print("The time taken was " + str(totalSec) + " seconds")
  114.  
  115. else:
  116. startTimeMin = startList[0] + startList[1]
  117. startTimeMin = int(startTimeMin)
  118. startTimeSec = startList[3] + startList[4]
  119. startTimeSec = int(startTimeSec)
  120.  
  121. finishTimeMin = finishList[0] + finishList[1]
  122. finishTimeMin = int(finishTimeMin)
  123. finishTimeSec = finishList[3] + finishList[4]
  124. finishTimeSec = int(finishTimeSec)
  125.  
  126. totalMin = finishTimeMin - startTimeMin
  127. totalSec = finishTimeSec - startTimeSec
  128. totalMinInSec = totalMin*60
  129. totalSec += totalMinInSec
  130.  
  131. print("The time taken was " + str(totalSec) + " seconds")
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140. #Take a random proxy from a list of proxies and return it
  141.  
  142. def findproxy():
  143. progfile =open("proxies.txt","r")
  144. position = 0
  145. proxylist = []
  146. for line in progfile:
  147. proxylist.append(1)
  148. proxylist[position]=line.strip("\n")
  149. position += 1
  150. print("There are " + str(position) + " proxies saved")
  151. proxy = random.choice(proxylist)
  152. return proxy
  153.  
  154. #Split the proxy into its IP, port, username and password
  155. def splitproxy(proxy):
  156. indproxy = proxy.split(":")
  157. PROXY_HOST = indproxy[0]
  158. PROXY_PORT = indproxy[1]
  159. try:
  160. PROXY_USER = indproxy[2]
  161. PROXY_PASS = indproxy[3]
  162. is_userpass = True
  163. except Exception:
  164. is_userpass = False
  165. return PROXY_HOST,PROXY_PORT,PROXY_USER,PROXY_PASS,is_userpass
  166.  
  167. def initialisebrowser(useproxy):
  168. if useproxy == True:
  169. proxy = findproxy()
  170. PROXY_HOST,PROXY_PORT,PROXY_USER,PROXY_PASS,is_userpass = splitproxy(proxy)
  171.  
  172. print("Using proxy: " + proxy)
  173.  
  174. if is_userpass == True:
  175.  
  176. manifest_json = """
  177. {
  178. "version": "1.0.0",
  179. "manifest_version": 2,
  180. "name": "Chrome Proxy",
  181. "permissions": [
  182. "proxy",
  183. "tabs",
  184. "unlimitedStorage",
  185. "storage",
  186. "<all_urls>",
  187. "webRequest",
  188. "webRequestBlocking"
  189. ],
  190. "background": {
  191. "scripts": ["background.js"]
  192. },
  193. "minimum_chrome_version":"22.0.0"
  194. }
  195. """
  196.  
  197. background_js = """
  198. var config = {
  199. mode: "fixed_servers",
  200. rules: {
  201. singleProxy: {
  202. scheme: "http",
  203. host: "%s",
  204. port: parseInt(%s)
  205. },
  206. bypassList: ["localhost"]
  207. }
  208. };
  209.  
  210. chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
  211.  
  212. function callbackFn(details) {
  213. return {
  214. authCredentials: {
  215. username: "%s",
  216. password: "%s"
  217. }
  218. };
  219. }
  220.  
  221. chrome.webRequest.onAuthRequired.addListener(
  222. callbackFn,
  223. {urls: ["<all_urls>"]},
  224. ['blocking']
  225. );
  226. """ % (PROXY_HOST, PROXY_PORT, PROXY_USER, PROXY_PASS)
  227.  
  228. def get_chromedriver(use_proxy=True,user_agent = None):
  229. path = os.path.dirname(os.path.abspath(__file__))
  230. chrome_options = webdriver.ChromeOptions()
  231. if use_proxy:
  232. pluginfile = 'proxy_auth_plugin.zip'
  233.  
  234. with zipfile.ZipFile(pluginfile, 'w') as zp:
  235. zp.writestr("manifest.json", manifest_json)
  236. zp.writestr("background.js", background_js)
  237. chrome_options.add_extension(pluginfile)
  238. browser = webdriver.Chrome(
  239. os.path.join(path, 'chromedriver'),
  240. chrome_options=chrome_options)
  241. return browser
  242.  
  243. browser = get_chromedriver(use_proxy=True,user_agent = None)
  244.  
  245. elif is_userpass == False:
  246.  
  247. address = PROXY_HOST + ":" + PROXY_HOST
  248. print("Using proxy: " + proxy)
  249. chrome_options = webdriver.ChromeOptions()
  250. chrome_options.add_argument('--proxy-server=%s' % address)
  251. browser = webdriver.Chrome(r'''chromedriver.exe''',chrome_options=chrome_options)
  252.  
  253. else:
  254. useproxy = False
  255. print("Invalid user:pass variable, running on Home IP")
  256. browser = webdriver.Chrome(r'''chromedriver.exe''')
  257. else:
  258. print("Using Home IP")
  259. browser = webdriver.Chrome(r'''chromedriver.exe''')
  260.  
  261. return browser
  262.  
  263. #Pass in the browser and url, and go to the url with the browser
  264. def geturl(browser, url):
  265. browser.get(url)
  266. #if useproxy == True:
  267. #webdriver.ActionChains(browser).send_keys("cop35477" + Keys.TAB + "cop9729").perform()
  268.  
  269. #Set up functions to remove cookie and email pop-ups
  270. def rejectcookies(browser):
  271. try:
  272. cookiesreject = WebDriverWait(browser, 1).until(EC.element_to_be_clickable((By.CLASS_NAME, 'js-closeCookieBanner')))
  273. cookiesreject.click()
  274. except:
  275. pass
  276.  
  277. def rejectemails():
  278. try:
  279. emailsreject = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, 'bx-button')))
  280. emailsreject.click()
  281. except:
  282. print("Email not found")
  283.  
  284. #Generates the email to be used to create the account
  285. def generatedata():
  286. forename=names.get_first_name(gender='male')
  287. surname = names.get_last_name()
  288.  
  289.  
  290. date = random.randint(1,28)
  291. if len(str(date))==1:
  292. date = "0" + str(date)
  293.  
  294. month = random.randint(1,12)
  295. if len(str(month))==1:
  296. month="0"+str(month)
  297.  
  298. year = random.randint(1985,2000)
  299. dob=str(date)+str(month)+str(year)
  300.  
  301. return forename,surname,dob,date,year
  302.  
  303. #filling the page with info and submitting it
  304. def autofill(browser,email,password,forename,surname,dob):
  305. created = False
  306. while created == False:
  307.  
  308. ## time.sleep(1)
  309.  
  310. ## openmenu = WebDriverWait(browser, 3).until(EC.element_to_be_clickable((By.CLASS_NAME,"cart-button")))
  311. ## openmenu.click()
  312.  
  313. ## time.sleep(1)
  314. ##
  315. ## loginbutton = browser.find_element_by_xpath("//*[@data-qa='join-login-button']")
  316. ## loginbutton.click()
  317.  
  318. ## time.sleep(0.5)
  319. ##
  320. ## joinbutton = browser.find_element_by_xpath("//*[contains(text(),'Join now.')]")
  321. ## joinbutton.click()
  322. time.sleep(5)
  323. emailbox = browser.find_element_by_name("emailAddress")
  324. emailbox.send_keys(email)
  325.  
  326. passwordbox = browser.find_element_by_name("password")
  327. passwordbox.send_keys(password)
  328.  
  329. forenamebox = browser.find_element_by_name("firstName")
  330. forenamebox.send_keys(forename)
  331.  
  332. surnamebox = browser.find_element_by_name("lastName")
  333. surnamebox.send_keys(surname)
  334.  
  335. dobbox = browser.find_element_by_name("dateOfBirth")
  336. dobbox.send_keys(dob)
  337.  
  338. malebutton = browser.find_element_by_xpath("//span[text() = 'Male']")
  339. malebutton.click()
  340.  
  341. createbutton = browser.find_element_by_class_name("nike-unite-submit-button")
  342. time.sleep(1)
  343. createbutton.click()
  344. try:
  345.  
  346. dismissbox = WebDriverWait(browser, 3).until(EC.element_to_be_clickable((By.CLASS_NAME, 'nike-unite-error-close')))
  347. dismissbox.click()
  348. created = False
  349.  
  350. try:
  351. alreadycreatedbox = WebDriverWait(browser, 5).until(EC.visibility_of_element_located((By.CLASS_NAME, 'duplicate-email')))
  352. print("Account already created. Please start again")
  353.  
  354. except Exception:
  355.  
  356. print("Server error. Attempting account creation again...")
  357. geturl(browser,"https://www.nike.com/gb/launch/")
  358. time.sleep(1)
  359.  
  360. except Exception:
  361.  
  362. print("Succesfully created and logged into account with email: '" + email + "' and password: '" + password + "'!")
  363. created = True
  364. time.sleep(5)
  365. pass
  366. ## inp = input("click enter when account is verified")
  367. ## geturl(browser,"chrome://settings/clearBrowserData")
  368.  
  369.  
  370. def signin(browser,email,created):
  371. loggedin = False
  372. login_attempts = 0
  373. while loggedin ==False:
  374.  
  375. emailtextbox = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.NAME, 'emailAddress')))
  376. emailtextbox.clear()
  377. emailtextbox.send_keys(email)
  378. pwtextbox = browser.find_element_by_name('password')
  379. pwtextbox.clear()
  380. pwtextbox.send_keys(password)
  381. delay = random.uniform(0.1,5)
  382. time.sleep(delay)
  383. pwtextbox.send_keys(Keys.ENTER)
  384. print("Logging in with email: '" + email + "' and password: '" + password + "'!")
  385. try:
  386. dismissbox = WebDriverWait(browser, 3).until(EC.element_to_be_clickable((By.CLASS_NAME, 'nike-unite-error-close')))
  387. dismissbox.click()
  388. login_attempts = login_attempts + 1
  389. loggedin = False
  390. print("Server error. Attempting login again...")
  391. geturl(browser,"https://store.nike.com/gb/en_gb/?l=shop,login_register")
  392. print("Delaying before login...")
  393. if login_attempts < 4:
  394. pass
  395. else:
  396. time.sleep(15)
  397.  
  398. except Exception:
  399. print("Successfully logged in")
  400. loggedin = True
  401. created=True
  402. print("Navigating to url")
  403. pass
  404.  
  405.  
  406. def restart(browser, email, password):
  407.  
  408. inp = input("press enter to restart program")
  409. progfile = open(accountlocation,"a")
  410. progfile.write(email + ":" + password + "\n")
  411. progfile.close()
  412. print("Saved account to " + accountlocation + "!")
  413.  
  414. print("Clearing cookies and logging out")
  415.  
  416.  
  417. browser.delete_all_cookies()
  418. print("Cleared all cookies!")
  419. geturl(browser,"https://www.nike.com/gb/launch/")
  420.  
  421.  
  422.  
  423. counter = 0
  424. global entirecounter
  425. entirecounter = -1
  426.  
  427. def run(counter):
  428.  
  429.  
  430.  
  431. while True:
  432. global entirecounter
  433. entirecounter += 1
  434. startList = getStartTime()
  435. accountList = readaccounts()
  436. email,password = getaccount(accountList)
  437. counter += 1
  438. if counter == 1:
  439. proxy = findproxy()
  440. PROXY_HOST,PROXY_PORT,PROXY_USER,PROXY_PASS,is_userpass = splitproxy(proxy)
  441.  
  442.  
  443. browser = initialisebrowser(useproxy)
  444.  
  445. geturl(browser,"https://www.nike.com/gb/launch/")
  446.  
  447. rejectcookies(browser)
  448.  
  449. box = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, 'join-log-in')))
  450. box.click()
  451.  
  452.  
  453. forename,surname,dob,date,year=generatedata()
  454.  
  455. autofill(browser,email,password,forename,surname,dob)
  456.  
  457. restart(browser,email,password)
  458. getFinalTime(startList)
  459.  
  460. if counter == 3 and useproxy == True:
  461. counter = 0
  462.  
  463.  
  464.  
  465. run(counter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement