0
import sys
sys.path.append(r'C:/Program Files (x86)/TourneAIO/TourneAIO/ALL IMPORTS')
import selenium
import requests
import random
import webbrowser
from colorama import Fore, Back, Style
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from colorama import init
import time
import pickle
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import NoSuchElementException
from bs4 import BeautifulSoup
from urllib.parse import urljoin
import uuid
import time
import requests

from datetime import datetime
init()


print(Style.BRIGHT)
print(Fore.CYAN + "            ------------- ")
print(Fore.CYAN + "           |             |")
print(Fore.CYAN + "            -------------     -------    ||       ||  ||--------||  || \     ||  ||--------                   ")
print(Fore.CYAN + "                 | |        ||-------||  ||       ||  ||--------||  ||\ \    ||  ||--------                   ")
print(Fore.CYAN + "                 | |        ||       ||  ||       ||  ||        ||  || \ \   ||  ||                           ")
print(Fore.CYAN + "                 | |        ||       ||  ||       ||  ||--------||  ||  \ \  ||  ||--------                   ")
print(Fore.CYAN + "                 | |        ||       ||  ||       ||  ||--------||  ||   \ \ ||  ||--------                   ")
print(Fore.CYAN + "                 | |        ||       ||  ||       ||  ||    \ \     ||    \ \||  ||                           ")
print(Fore.CYAN + "                 | |        ||       ||  ||       ||  ||     \ \    ||     \ ||  ||                           ")
print(Fore.CYAN + "                 ---        ||-------||  ||-------||  ||      \ \   ||      \||  ||--------                   ")
print(Fore.CYAN + "                 ---          -------      -------    ||       \ \  ||       ||  ||--------                   ")
print('')
print('Welcome To TourneAIO')
print('')
print('dev kroo & zora')
print(Fore.GREEN + '')
item=input('Enter PID: ')
monitor=int(input('Enter Delay(s): '))
print(Style.RESET_ALL)
options = Options()
options.page_load_strategy = 'eager'
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
prefs = {"profile.managed_default_content_settings.images": 2}
options.add_experimental_option("prefs", prefs)
options.headless = False
options.add_argument("--window-size=1920,1080")
options.add_argument('--ignore-certificate-errors')
options.add_argument('--allow-running-insecure-content')
options.add_argument("--disable-extensions")
options.add_argument("--proxy-server='direct://'")
options.add_argument("--proxy-bypass-list=*")
options.add_argument("--start-maximized")
options.add_argument('--disable-gpu')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--no-sandbox')
driver=webdriver.Chrome(executable_path='C:/Program Files (x86)/TourneAIO/TourneAIO/chromedriver.exe',options=options)
driver.get('https://www.currys.co.uk/gbuk/-/-'+item+'-pdt.html')


    


def cookie():
    print(Fore.GREEN + '')
    print("getting session")
    WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="onetrust-accept-btn-handler"]'))).click()
    print("-----------------------")
    print("accepted cookies")
    request_cookies_browser = driver.get_cookies()
def productname():
    while True:
        try:
            global product
            print("-----------------------")
            product=driver.find_element(By.XPATH,'//*[@id="content"]/div[2]/section/div[2]/h1').text
            print('Found Product:',product)
            break
        except:
            driver.refresh()
            print(Fore.RED + "")
            res=requests.get('https://www.currys.co.uk/gbuk/-/-'+item+'-pdt.html')
            print(res.status_code)
            if res.status_code==404:
                print("Inavalid product Or Product Not Found Retrying")
                res.close()
                time.sleep(monitor)
                productname()
            else:
                print("RequestTimedOut")
                print(Style.RESET_ALL)
                cookie()
               
def checkstock():
    try:
        l=driver.find_element_by_xpath('//*[@id="product-actions"]/div[4]/div[1]/button')
        l.click()
        print("-----------------------")
        print('Item in basket')
        print("-----------------------")
        print("beggining checkout")
        print("-----------------------")
    except NoSuchElementException:
        print(Fore.RED + "")
        print("-----------------------")
        print("Product OOS Retrying With",monitor,"Delay")
        print(Style.RESET_ALL)
        time.sleep(monitor)
        driver.refresh()
        checkstock()
def checkout():
    time.sleep(0.5)
    driver.get('https://www.currys.co.uk/app/checkout')
    print('Submitting Address')
    sndpost=WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[4]/div/div[2]/div[2]/div[2]/div/div/div[2]/div[2]/div[2]/div/div/div/div[1]/form/input')))
    sndpost.send_keys('SE92JN')
    driver.click('/html/body/div[4]/div/div[2]/div[2]/div[2]/div/div/div[2]/div[2]/div[2]/div/div/div/div[1]/form/button[2]')
    
    
    
    
    
    

    

                     
cookie()
productname()
checkstock()
checkout()

i want to use this code but make it faster and i know its using requests, so not opening in a chromdriver or chromium driver simply communicating completely through requests to add to basket and checkout.Any help will be very much appreciated or anything to contribute. Thank you!

anything will help please need this code done? i only know python

0 Answers0