def readGapProductsFile(): returnValues = [] href = "" counter34 = 0 spareChars = 0 hrefFlag = False with open("result.txt", mode='r') as ProdcutsFile: readCSV = csv.reader(ProdcutsFile) for row in readCSV: for char in row: # 'href' case if hrefFlag: answer, = hrefCase(href, char, counter34, spareChars) if (href == None or href == '') and answer == False: # Not found href = savingAttribute hrefFlag = False if (href != None and href != '') and answer == False: # Found href hrefFlag = False # In case that all the attributes were built - Create an instance of Product and start again if (href != "" and hrefFlag == False): returnValues.append( GapProduct.Product(names, hrefs, img, prices, dire)) # Initialize all the attributes and flags numberOfCharsFromImgToSec = spareChars = counter34 = 0
def readFromResult(): lines = [ "names", "hrefs", "img", "prices", "", "", "", "Enter", ] lines_index = 0 names = [] hrefs = [] gapProducts = [] gapProducts_index = 0 with open("GapProducts.txt", mode='r') as ProdcutsFile: readCSV = csv.reader(ProdcutsFile) for row in readCSV: if lines[lines_index] == "names": names = row if lines[lines_index] == "hrefs": hrefs = row if lines[lines_index] == "Enter": gapProducts.insert( gapProducts_index, GapProduct.Product(names, hrefs, "", "", "", "", "")) gapProducts_index = gapProducts_index + 1 names = [] hrefs = [] lines_index = 0 lines_index = lines_index + 1 return gapProducts
def getStoreProductDetails(storeProduct): hrefs = [storeProduct.site1_url, storeProduct.site2_url] # Connect to Data Base conn = pyodbc.connect(r'Driver={SQL Server};'r'Server=DESKTOP-SAE8VJG\GINOSQLSERVER;'r'Database=AutomaticDropshippingDB;'r'Trusted_Connection=yes;') cursor = conn.cursor() # Makes a query cursor.execute("SELECT * FROM [dbo].[GapsAmazonEbayProducts] WHERE [dbo].[GapsAmazonEbayProducts].[HREFS] = ?", str(hrefs)) try: for row in cursor: product = GapProduct.Product(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8]) return product except: None
def readAllTable(tableName): # Connect to Data Base conn = pyodbc.connect(r'Driver={SQL Server};'r'Server=DESKTOP-SAE8VJG\GINOSQLSERVER;'r'Database=AutomaticDropshippingDB;'r'Trusted_Connection=yes;') cursor = conn.cursor() cursor.setinputsizes([(pyodbc.SQL_WVARCHAR, 0, 0)]) # Coax pyodbc into treating [N]TEXT columns like [n]varchar(max) columns # Makes a query cursor.execute('SELECT * FROM [dbo].[' + tableName + ']') # Turns each row into the appropriate structure returnProduct = [] returnProduct_Index = 0 try: for row in cursor: if tableName == Constances.AMAZON_PRODUCTS_TABLE: try: product = Amazon.Product(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8]) returnProduct.insert(returnProduct_Index, product) returnProduct_Index = returnProduct_Index + 1 except: None if tableName == Constances.EBAY_PRODUCTS_TABLE: try: product = Ebay.Product(row[0], row[1], row[2], row[3], row[4], row[5]) returnProduct.insert(returnProduct_Index, product) returnProduct_Index = returnProduct_Index + 1 except: None if tableName == Constances.PRODUCTS_DESTANCES_TABLE: try: product = ProductDestance.Product(row[0], row[1], row[2]) returnProduct.insert(returnProduct_Index, product) returnProduct_Index = returnProduct_Index + 1 except: None if tableName == Constances.GAPS_AMAZON_EBAY_PRODUCTS_TABLE: try: product = GapProduct.Product(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8]) returnProduct.insert(returnProduct_Index, product) returnProduct_Index = returnProduct_Index + 1 except: None if tableName == Constances.STORE_PRODUCTS_TABLE: try: product = StoreProduct.Product(row[0], row[1], row[2], row[3]) returnProduct.insert(returnProduct_Index, product) returnProduct_Index = returnProduct_Index + 1 except: None return returnProduct except Exception as e: print(e) # The file does not exists print("Error - The table " + tableName + " does not exists") return None
def getProduct(tableName, productKey): # Connect to Data Base conn = pyodbc.connect(r'Driver={SQL Server};'r'Server=DESKTOP-SAE8VJG\GINOSQLSERVER;'r'Database=AutomaticDropshippingDB;'r'Trusted_Connection=yes;') cursor = conn.cursor() # Makes a query if tableName == Constances.AMAZON_PRODUCTS_TABLE: cursor.execute("SELECT * FROM [dbo].[" + tableName + "] WHERE [dbo].[" + tableName + "].ASIN = ?", str(productKey)) # Makes a query if tableName == Constances.EBAY_PRODUCTS_TABLE: cursor.execute("SELECT * FROM [dbo].[" + tableName + "] WHERE [dbo].[" + tableName + "].HREF = ?", str(productKey)) # Makes a query if tableName == Constances.PRODUCTS_DESTANCES_TABLE: cursor.execute("SELECT * FROM [dbo].[" + tableName + "] WHERE [dbo].[" + tableName + "].IMAGE = ?", str(productKey)) # Makes a query if tableName == Constances.GAPS_AMAZON_EBAY_PRODUCTS_TABLE: cursor.execute("SELECT * FROM [dbo].[" + tableName + "] WHERE [dbo].[" + tableName + "].HREFS = ?", str(productKey)) # Makes a query if tableName == Constances.STORE_PRODUCTS_TABLE: cursor.execute("SELECT * FROM [dbo].[" + tableName + "] WHERE [dbo].[" + tableName + "].SITE1_URL = ? and [dbo].[" + tableName + "].SITE2_URL = ?", productKey[0], productKey[1]) try: for row in cursor: if tableName == Constances.AMAZON_PRODUCTS_TABLE: try: product = Amazon.Product(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8]) except: None if tableName == Constances.EBAY_PRODUCTS_TABLE: try: product = Ebay.Product(row[0], row[1], row[2], row[3], row[4], row[5]) except: None if tableName == Constances.PRODUCTS_DESTANCES_TABLE: try: product = ProductDestance.Product(row[0], row[1], row[2]) except: None if tableName == Constances.GAPS_AMAZON_EBAY_PRODUCTS_TABLE: try: product = GapProduct.Product(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8]) except: None if tableName == Constances.STORE_PRODUCTS_TABLE: try: product = StoreProduct.Product(row[0], row[1], row[2], row[3]) except: None return product except Exception as ex: # The file does not exists print(ex) return None
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)
def findGaps(): print("Finding gap products...") amazonProductsIndex = 0 ebayProductIndex = 0 try: # Gets the data from the DataBase AmazonData = SQLHandler.readAllTable(Constances.AMAZON_PRODUCTS_TABLE) EbayData = SQLHandler.readAllTable(Constances.EBAY_PRODUCTS_TABLE) if AmazonData == None or EbayData == None: return None # No data # Run over the products from AmazonData # For each Amazon product cross-referencing with products from EbayDaya with the same category for amazonProduct in AmazonData: ebayProductIndex = 0 # Search for ebay categories that can be similiar to amazonProduct.category for similar_categories in Constances.similar_categories_Amazon_Ebay: for category in similar_categories[0]: # Amazon if amazonProduct.category == category: ebayCategories = similar_categories[ 1] # Saves the Ebay categories # Create images at 'Products image before convert' and 'Products image after convert' folders for ebayProduct in EbayData: # Check if ebayProduct.category is similiar to amazonProduct.category checkFlag = False for category in ebayCategories: if ebayProduct.category == category: checkFlag = True if checkFlag: try: start = time.time() # Names similartion isNameSimilarAnswer = isNameSimilar( amazonProduct.name, ebayProduct.name) if isNameSimilarAnswer >= Constances.MINIMUM_VALUE_NAME_SIMILAR: # Images similartion - Only when names are similar # isImageSimilarAnswer[0] = Number of matches ; isImageSimilarAnswer[1] = avarage distances # Gets the products's destances from the data base amazonProductDestance = getDestance( amazonProduct.img, "Amazon") ebayProductDestance = getDestance( ebayProduct.img, "Ebay") # Convert from string amazonProductDestance = queryDestanceToNormal( amazonProductDestance) ebayProductDestance = queryDestanceToNormal( ebayProductDestance) isImageSimilarAnswer = ImageSimilartion.isImageSimilar( amazonProductDestance, ebayProductDestance) # Checks threshold if (isImageSimilarAnswer[0] >= Constances. MINIMUM_VALUE_IMAGE_NUMBER_OF_MATCHES and isImageSimilarAnswer[1] <= Constances. MAXIMUM_VALUE_IMAGE_AVARAGE_DISTANCES): # Found two products with similar images and names if float(amazonProduct.price) < float( ebayProduct.price): direction = 'Ebay_Dropshipping_Direction' else: direction = 'Amazon_Dropshipping_Direction' end = time.time() searchingTime = end - start gapProduct = GapProduct.Product( str([amazonProduct.name, ebayProduct.name]), str([amazonProduct.href, ebayProduct.href]), str([amazonProduct.img, ebayProduct.img]), str([ amazonProduct.price, ebayProduct.price ]), direction, amazonProduct.category, searchingTime, str(isNameSimilarAnswer), str(isImageSimilarAnswer)) SQLHandler.addProduct( Constances.GAPS_AMAZON_EBAY_PRODUCTS_TABLE, gapProduct) # If there is cheaper product on Ebay - No need to continue due to the structure of Ebay if direction == 'Amazon_Dropshipping_Direction': break # Move on to the next amazon product except Exception as e: print(e) # Prints the Error ebayProductIndex = ebayProductIndex + 1 amazonProductsIndex = amazonProductsIndex + 1 except Exception as e: print(e) # Prints the Error print("Finish finding gaps.")