Ejemplo n.º 1
0
def getTheProducts_multiURLs():
    print("Collecting from Ebay...")
    HTML_content_by_Categories = Constances.ebay_categories
    categories_index = 0
    # Get a WebDriver
    driver = driverStarter.startDriver()
    for url in HTML_content_by_Categories:
        # Name of category
        category_name = Constances.ebay_categories_names[categories_index]
        answer = driverStarter.effectiveGet(driver, url)
        numberOfPageCounter = 1
        while answer == True:
            content = driver.page_source
            # Encode & Decode the source data and decode again for string type only
            readable_content = content.encode(sys.stdout.encoding,
                                              errors='replace').decode(
                                                  'utf-8', errors='ignore')
            # Split and Seek products
            url_products = getTheProducts_singleURL(readable_content,
                                                    category_name)
            for product in url_products:
                # Adds the new products to the DataBase
                SQLHandler.addProduct(Constances.EBAY_PRODUCTS_TABLE, product)
            answer = Tools.nextPage(driver)
            numberOfPageCounter = numberOfPageCounter + 1
            if numberOfPageCounter > Constances.LIMIT_NUMBER_OF_PAGE_TO_SEARCH:
                answer = False
        categories_index = categories_index + 1
    print("Finish Collecting from Ebay.")
    driver.close()
Ejemplo n.º 2
0
def checkGapProducts():
    # Initialize
    driver = driverStarter.startDriver()
    # Get the gap products from data base
    GapData_AmazonEbay = SQLHandler.readAllTable(Constances.GAPS_AMAZON_EBAY_PRODUCTS_TABLE)
    for gapProduct in GapData_AmazonEbay:
        try:
            # Convert the hrefs from string type
            hrefs = gapProduct.hrefs.replace("[", "").replace("]", "").replace("'", "").replace(" ", "").split(",")
            names = splitName(gapProduct.names)
            names[0] = names[0].replace("'", "") # Amazon product name
            names[1] = names[1].replace("'", "") # Ebay product name
            imgs = gapProduct.imgs.replace("[", "").replace("]", "").replace("'", "").split(",")
            # Check if the gap product is already in Constances.STORE_PRODUCTS_TABLE
            isInStore = SQLHandler.isProduct(Constances.STORE_PRODUCTS_TABLE, [hrefs[0], hrefs[1]])
            if isInStore == False:
                if gapProduct.direction == 'Amazon_Dropshipping_Direction':
                    # The store should be open on Amazon while the product is being shipped from eBay
                    # Starts with the first href - Amazon site - Checking if the site is correct
                    isHrefAmazonCorrect = driverStarter.effectiveGet(driver, hrefs[0]) # Checking if the href is correct
                    if isHrefAmazonCorrect:
                        isCorrect_Amazon = checkIfPersonalSite_Amazon(driver) # Checking if product personal site
                        if isCorrect_Amazon == False: hrefs[0] = getTheCorrectSite_Amazon(driver, names[0], imgs[0])
                        isHrefEbayCorrect = driverStarter.effectiveGet(driver, hrefs[1]) # Ebay
                        if isHrefEbayCorrect:
                            # First - Checking if personal product site
                            isPersonal = checkIfPersonalSite_Ebay(driver)
                            if isPersonal:
                                ''' Just for this version - Only free shipping - Only USA!
                                # Checking the shipping details and options
                                shipping = checkShippingEbay(driver) # A browser must be open before with the appropriate site
                                # Just for this version - Only free shipping
                                if shipping == 'Free Shipping':
                                '''
                                # Safe to upload! - Add to data base
                                storeProduct = StoreProduct.Product(hrefs[0], hrefs[1], "Amazon", Constances.STATUS_NOT_UPLOAD)
                                SQLHandler.addProduct(Constances.STORE_PRODUCTS_TABLE, storeProduct)
                        else: deleteGap(gapProduct, "Ebay")
                    else: deleteGap(gapProduct, "Amazon")
                if gapProduct.direction == 'Ebay_Dropshipping_Direction':
                    # The store should be open on Ebay while the product is being shipped from Amazon
                    # Due to the structure of Ebay - there is no need to check if the site exists or is working properly
                    ''' Just for this version - Only free shipping - Only USA!
                    # Checking the shipping details and options in Amazon site
                    shipping = checkShippingAmazon(driver) # A browser must be open before with the appropriate site
                    # Just for this version - Only free shipping
                    # Selling only in USA
                    if shipping == 'Free Shipping':
                    '''
                    # Safe to upload! - Add to data base
                    storeProduct = StoreProduct.Product(hrefs[0], hrefs[1], "Ebay", Constances.STATUS_NOT_UPLOAD)
                    SQLHandler.addProduct(Constances.STORE_PRODUCTS_TABLE, storeProduct)
        except: None
Ejemplo n.º 3
0
import sys
from Collection import Ebay
from Initialization import driverStarter

driver = driverStarter.startDriver()
url_ebay_Electronics_Search = 'https://www.ebay.com/sch/i.html?_sacat=0&_udlo=&_udhi=&_ftrt=901&_ftrv=1&_sabdlo=&_sabdhi=&_samilow=&_samihi=&_sadis=15&_stpos=22747&_sop=12&_dmd=1&_fosrp=1&LH_ItemCondition=3&_nkw=electronics&_pgn=1'
driverStarter.effectiveGet(driver, url_ebay_Electronics_Search)
content = driver.page_source
# Encode & Decode the source data and decode again for string type only
readable_content = content.encode(sys.stdout.encoding,
                                  errors='replace').decode('utf-8',
                                                           errors='ignore')
Ebay.getTheProducts_singleURL(readable_content, '')
Ejemplo n.º 4
0
def uploadProducts():
    # Initialize
    storeProducts = SQLHandler.readAllTable(Constances.STORE_PRODUCTS_TABLE)
    # Open store at the specific location
    try:
        # Open the stores (Amazon and Ebay)
        # Just for this version - Manually!
        print(
            "Open Ebay store... (Please update 'UserOrders.txt' after finish!)"
        )
        ebayDriver = driverStarter.startDriver()
        driverStarter.effectiveGet(ebayDriver, Constances.EBAY_SITE)
        # Just for this version - The program knows the store are opened only when there is an update on DataBase
        answer = SQLHandler.isStoresOpen()
        while answer == False:
            answer = SQLHandler.isStoresOpen()
        # Update DataBase
        SQLHandler.updateUserOrderTable()
        print("The phase of opening store has ended")
    except Exception as e:
        print("The code stopped because: " + e)
    # Run over the data and uploading to Ebay store
    searchBarElement_Ebay = None
    continueElement_Ebay = None
    ignored_exceptions = (
        NoSuchElementException,
        StaleElementReferenceException,
    )
    for storeProduct in storeProducts:
        if storeProduct.status == Constances.STATUS_NOT_UPLOAD:
            if storeProduct.store_location == 'Ebay':  # Ebay cases
                # Gets the full data of the store product from gap products table
                gapProduct = SQLHandler.getStoreProductDetails(storeProduct)
                names = availableProduct.splitName(gapProduct.names)
                imgs = gapProduct.imgs.replace("[",
                                               "").replace("]", "").replace(
                                                   "'", "").split(", ")
                prices = gapProduct.prices.replace("[", "").replace(
                    "]", "").replace("'", "").split(", ")
                # In ebayDriver - search for the search bar element and searching for the name of the product
                if searchBarElement_Ebay == None:
                    iframe = ebayDriver.find_element_by_xpath(
                        Constances.EBAY_SELLING_PRODCUT_SEARCH_BAY_IFRAME)
                    ebayDriver.switch_to.frame(iframe)  # Switch to iframe
                    searchBarElement_Ebay = WebDriverWait(ebayDriver, 10, ignored_exceptions=ignored_exceptions)\
                                            .until(EC.presence_of_element_located((By.ID, Constances.EBAY_SELLING_PRODUCT_SEARCH_BAR_KEY)))
                searchBarElement_Ebay.send_keys(names[1] + "\n")  # Ebay
                # Continue to the 'Create a list' page
                if continueElement_Ebay == None:
                    continueElement_Ebay = WebDriverWait(ebayDriver, 20, ignored_exceptions=ignored_exceptions)\
                                            .until(EC.presence_of_element_located((By.XPATH, Constances.EBAY_SELLING_PRODUCT_CONTINUE)))
                continueElement_Ebay.click()
                # Fills in the fields
                ebayDriver.switch_to.default_content(
                )  # Get out from the iframe
                #   UPC
                upcElement = WebDriverWait(ebayDriver, 20, ignored_exceptions=ignored_exceptions)\
                                            .until(EC.presence_of_element_located((By.XPATH, Constances.EBAY_SELLING_CREATE_A_LIST_UPC)))
                upcElement.click()
                #   Condition
                WebDriverWait(ebayDriver, 20, ignored_exceptions=ignored_exceptions)\
                                            .until(EC.presence_of_element_located((By.XPATH, Constances.EBAY_SELLING_CREATE_A_LIST_UPC_OPTION_2))).click()
                conditionElement = WebDriverWait(ebayDriver, 20, ignored_exceptions=ignored_exceptions)\
                                            .until(EC.presence_of_element_located((By.XPATH, Constances.EBAY_SELLING_CREATE_A_LIST_CONDITION)))
                conditionElement.send_keys("New")
                #   Photos
                iframe = ebayDriver.find_element_by_id(
                    Constances.EBAY_SELLING_CREATE_A_LIST_PHOTOS_IFRAME)
                ebayDriver.switch_to.frame(iframe)  # Switch to iframe
                importFromWebElement = WebDriverWait(ebayDriver, 20, ignored_exceptions=ignored_exceptions)\
                                            .until(EC.presence_of_element_located((By.XPATH, Constances.EBAY_SELLING_CREATE_A_LIST_IMPORT_IMAGE_FROM_WEB)))
                importFromWebElement.click()
                enterImageURLElement = WebDriverWait(ebayDriver, 20, ignored_exceptions=ignored_exceptions)\
                                            .until(EC.presence_of_element_located((By.XPATH, Constances.EBAY_SELLING_CREATE_A_LIST_ENTER_IMAGE_URL)))
                enterImageURLElement.send_keys(
                    imgs[0])  # Using Amazon's product's image
                importImageButtonElement = WebDriverWait(ebayDriver, 20, ignored_exceptions=ignored_exceptions)\
                                            .until(EC.presence_of_element_located((By.XPATH, Constances.EBAY_SELLING_CREATE_A_LIST_IMPORT_IMAGE_BUTTON)))
                importImageButtonElement.click()
                ebayDriver.switch_to.default_content(
                )  # Get out from the iframe
                #   Brand
                brandElement = WebDriverWait(ebayDriver, 20, ignored_exceptions=ignored_exceptions)\
                                            .until(EC.presence_of_element_located((By.XPATH, Constances.EBAY_SELLING_CREATE_A_LIST_BRAND)))
                brandElement.send_keys("Unbranded")
                #   MPN
                MPNElement = WebDriverWait(ebayDriver, 20, ignored_exceptions=ignored_exceptions)\
                                            .until(EC.presence_of_element_located((By.XPATH, Constances.EBAY_SELLING_CREATE_A_LIST_MPN)))
                MPNElement.send_keys("Does Not Apply")
                #   Item description
                iframe = ebayDriver.find_element_by_id(
                    Constances.
                    EBAY_SELLING_CREATE_A_LIST_ITEM_DESCRIPTION_IFRAME)
                ebayDriver.switch_to.frame(iframe)  # Switch to iframe
                itemDescriptionElement = WebDriverWait(ebayDriver, 20, ignored_exceptions=ignored_exceptions)\
                                            .until(EC.presence_of_element_located((By.XPATH, Constances.EBAY_SELLING_CREATE_A_LIST_ITEM_DESCRIPTION_TEXT)))
                itemDescriptionElement.send_keys(
                    names[1]
                )  # Just for this version - The name is the item description
                ebayDriver.switch_to.default_content(
                )  # Get out from the iframe
                #   Selling details
                sellingDetailsElement = WebDriverWait(ebayDriver, 20, ignored_exceptions=ignored_exceptions)\
                                            .until(EC.presence_of_element_located((By.XPATH, Constances.EBAY_SELLING_CREATE_A_LIST_SELLING_DETAILS)))
                sellingDetailsElement.click()
                sellingDetailsElement.send_keys(Keys.DOWN)
                sellingDetailsElement.send_keys(9)  # Tab
                sellingDetailsElement.click()
                time.sleep(5)  # Saves and updates information
                priceElement = WebDriverWait(ebayDriver, 20, ignored_exceptions=ignored_exceptions)\
                                            .until(EC.presence_of_element_located((By.XPATH, Constances.EBAY_SELLING_CREATE_A_LIST_SELLING_DETAILS_PRICE)))
                pricesRatio = float(prices[0]) / float(
                    prices[1])  # The maximum profit price
                # Just for this version - 10% off from ebay price
                # For example - Amazon price (10$); Ebay price (15$)
                #               Maximum profit price is 5$ (pricesRatio = 0.666...)
                #               The price on our store (pricesRatio * 1.1 * EbayPrice = 11$)
                #               Our profit price is 4$
                priceElement.send_keys(
                    str(pricesRatio * 1.1 * float(prices[1])))
                payPalChooseElement = WebDriverWait(ebayDriver, 20, ignored_exceptions=ignored_exceptions)\
                                            .until(EC.presence_of_element_located((By.XPATH, Constances.EBAY_SELLING_CREATE_A_LIST_SELLING_PAYPAL)))
                payPalChooseElement.click()
                receivingPaymentEmailTextElement = WebDriverWait(ebayDriver, 20, ignored_exceptions=ignored_exceptions)\
                                                    .until(EC.presence_of_element_located((By.XPATH, Constances.EBAY_SELLING_CREATE_A_LIST_SELLING_RECEIVING_PAYMENT_EMAIL)))
                receivingPaymentEmailTextElement.send_keys(
                    Constances.AD_GINO_TEAM_EMAIL)

                #   Lists the item
                listItemElement = WebDriverWait(ebayDriver, 20, ignored_exceptions=ignored_exceptions)\
                                                    .until(EC.presence_of_element_located((By.XPATH, Constances.EBAY_SELLING_CREATE_A_LIST_LIST_ITEM)))
                listItemElement.click()
    print("Finish")  # Just for test
Ejemplo n.º 5
0
def findGaps():
    global driver
    # Gets data from data base
    AmazonData = SQLHandler.readAllTable(Constances.AMAZON_PRODUCTS_TABLE)
    EbayData = SQLHandler.readAllTable(Constances.EBAY_PRODUCTS_TABLE)
    # Creates a driver
    driver = driverStarter.startDriver()
    # Install PriceBlink
    initialize_Tools.initChrome_PriceBlink(driver)
    # Checking Amazon
    for amazonProduct in AmazonData:
        answer = driverStarter.effectiveGet(driver, amazonProduct.href)
        if answer:
            try:
                start = time.time(
                )  # Start counting the time for all the gap products reference to amazonProduct
                # Switch and wait for PriceBlink iframe
                wait(driver, Constances.
                     PRICE_BLINK_TIME_TO_WAIT_FOR_TOOLBAR_TO_LOAD).until(
                         EC.frame_to_be_available_and_switch_to_it(
                             Constances.PRICE_BLINK_IFRAME_ID))
                # Looking for the compare price button
                for element in driver.find_elements_by_id("comparePricesBtn"):
                    comparePriceElement = element
                comparePriceElement.click()  # Open the list
                listOfProducts = comparePriceElement.find_element_by_class_name(
                    Constances.PRICE_BLINK_LIST_CLASS_NAME
                )  # Looking for the list by class name
                # Gets all the product from the list
                priceBlinkProducts = []
                for product in listOfProducts.find_elements_by_class_name(
                        Constances.PRICE_BLINK_PRODUCT_CLASS_NAME):
                    priceBlinkProducts.append(product)
                # Creates the gap product list
                # Gets the price and the href attributes that write in the text for each product
                gapProductList_BeforeTime = []
                for product in priceBlinkProducts:
                    try:
                        time.sleep(Constances.
                                   PRICE_BLINK_TIME_TO_WAIT_FOR_PRICES_TO_LOAD)
                        # Get the price and the shipping
                        priceText = product.text
                        price, shipping = getPriceFromText(
                            priceText)  # Get the price
                        if shipping == 'FREE': shipping = '0.0'
                        # Determing direction of dropshipping
                        if (shipping != None and
                            (float(price) + float(shipping) < float(
                                amazonProduct.price)) or
                            (shipping == None
                             and float(price) < float(amazonProduct.price))):
                            direction = 'Amazon_Dropshipping_Direction'
                        else:
                            direction = 'Ebay_Dropshipping_Direction'
                        # Try to get the href of the product
                        try:
                            href = None
                            for element in product.find_elements_by_xpath(
                                    ".//*"):
                                try:
                                    # Should be only one href attribute in the product
                                    href = element.get_attribute('href')
                                    break
                                except:
                                    None
                            if href != None:  # Found href
                                isPersonalSite = checkIfPersonalSite(
                                    amazonProduct.href
                                )  # Checking if the site is for personal product
                                if isPersonalSite:  # PriceBlink finds a gap!
                                    # Gets the product name
                                    ebayProductName = ""
                                    # Gets the product image
                                    ebayProductImage = ""
                                    # Category is the same as Amazon
                                    # Simialrity is not calculated (None for both names and images similarity)
                                    gapProductList_BeforeTime.append([
                                        str([
                                            amazonProduct.name, ebayProductName
                                        ]),
                                        str([amazonProduct.href, href]),
                                        str([
                                            amazonProduct.img, ebayProductImage
                                        ]),
                                        str([amazonProduct.price,
                                             price]), direction,
                                        amazonProduct.category, "None", "None"
                                    ])
                        except:
                            None
                    except:
                        None
                end = time.time()  # Stop counting the time
                searchingTimeAllProducts = end - start
                searchingTimeEachProduct = searchingTimeAllProducts / len(
                    gapProductList_BeforeTime)
                for gapProduct_BeforeTime in gapProductList_BeforeTime:
                    gapProduct = GapProduct.Product(
                        gapProduct_BeforeTime[0], gapProduct_BeforeTime[1],
                        gapProduct_BeforeTime[2], gapProduct_BeforeTime[3],
                        gapProduct_BeforeTime[4], gapProduct_BeforeTime[5],
                        searchingTimeEachProduct, gapProduct_BeforeTime[6],
                        gapProduct_BeforeTime[7])
                    SQLHandler.addProduct(
                        Constances.GAPS_AMAZON_EBAY_PRODUCTS_TABLE, gapProduct)
                # Switch back
                driver.switch_to.default_content()
            except:
                None
    # Checking Ebay
    for ebayProduct in EbayData:
        answer = driverStarter.effectiveGet(driver, ebayProduct.href)