def Search(Title): ScrollFramePosition = [ScreenSize[0]/2-20,ScreenSize[1]-100,ScreenSize[0]/2+10,50]# Width,Height,X,Y # Search from cached or web Prices, FinalSearchName, SearchedItems = Get.AvgPrice(None,Title,0,0,Title,0,AvgPriceDataBase1,ErrorsDataBase1,UPCDataBase1) FrameIndex = [str(a) for a in ImageWidgets] for ItemIndex in range(len(FrameIndex)): if('verticalscrolledframe' in FrameIndex[ItemIndex]): ImageWidgets[ItemIndex].destroy() # Place scrolled frame frame1 = VerticalScrolledFrame(MainWindow, height=ScrollFramePosition[1], width=ScrollFramePosition[0], bd=2, relief=SUNKEN) frame1.place(x=ScrollFramePosition[2], y=ScrollFramePosition[3]) ImageWidgets.append(frame1) #Duplicate text from PackImageFromURL, Move to function Links = [] def AddLinkToText(PositionInLinks,URL): Links[PositionInLinks].bind("<Button-1>", lambda e: OpenInBrowzer(URL)) p = 0 rowCount = 5 Images = [] for i in SearchedItems: Images.append(i[1]) LoadImages(Images) for i in SearchedItems: if (i[1] != ""): ImageData = GetImageData(i[1], 500, 500) if ImageData == None: pass render = ImageTk.PhotoImage(ImageData) img = Label(frame1.interior, image=render) img.image = render # Create Image Widget ImageWidgets.append(img) img.grid(row=p * rowCount, column=0, rowspan=5) WrapLength = 400 link1 = Label(frame1.interior, text=SimplifyString(str(i[2])), fg="blue", cursor="hand2", wraplength=WrapLength) link1.config(font=("Comic Sans MS", 15)) ImageWidgets.append(link1) link1.grid(row=p * rowCount, column=1) Links.append(link1) AddLinkToText(p, i[0]) link1 = Label(frame1.interior, text=SimplifyString(str(i[3])), wraplength=WrapLength) link1.config(font=("Comic Sans MS", 15)) link1.grid(row=p * rowCount + 1, column=1) p = p + 1
def Analisis(ItemsList): OutOfCalls = 0 global MaxCalls driver = None UPCDataBase = TinyDB( os.path.dirname(os.path.dirname(__file__)) + "/DataBase/LinkToUPC") ShippingDataBase = TinyDB( os.path.dirname(os.path.dirname(__file__)) + "/DataBase/LinkToShipping") AvgPriceDataBase = TinyDB( os.path.dirname(os.path.dirname(__file__)) + "/DataBase/LinkToAvgPrice") ErrorsDataBase = TinyDB( os.path.dirname(os.path.dirname(__file__)) + "/Logs/Errors") WebDriverPath = os.path.dirname( os.path.dirname(__file__)) + '/Drivers/chromedriver.exe' TotalCount = len(ItemsList) # Total Count of items to search if (MaxCalls == 0): # No maximum call count CallCount = len(ItemsList) elif MaxCalls > len(ItemsList): # More calls than items CallCount = len(ItemsList) else: # Call count is limited by Maximum calls CallCount = MaxCalls LastCycle = time.time() * 2 # Record cycle time for time predictions RecordedCycleTime = [] # Initilize empty time per cycle array for Item in range(CallCount): # For every item CycleTime = time.time( ) - LastCycle # Calculate time it took for last item to be analized RecordedCycleTime.append(CycleTime) # Keep track of number # If more than 300 numbers remove the first number in the list, or if the first number is negative and there is more than one number if (len(RecordedCycleTime) > 300 or (RecordedCycleTime[0] < 0 and len(RecordedCycleTime) >= 2)): RecordedCycleTime = RecordedCycleTime[1:len(RecordedCycleTime)] # Calculate expected time remaining in mins ExpectedTimeRemaining = statistics.mean(RecordedCycleTime) * ( TotalCount - Item) / 60 LastCycle = time.time() # Record start time for analysis # Get Item information ItemSearchKeywords = ItemsList[Item]['SearchKeywords'] ItemURL = ItemsList[Item]['viewItemURL'][0] ItemTitle = ItemsList[Item]['title'][0] ItemUPC = Get.UPC(ItemURL, UPCDataBase) ItemPrice = ItemsList[Item]['sellingStatus'][0][ 'convertedCurrentPrice'][0]['__value__'] ItemShippingType = ItemsList[Item]['shippingInfo'][0]['shippingType'][ 0] try: ItemPicture = ItemsList[Item]['pictureURLSuperSize'][0] except: try: ItemPicture = ItemsList[Item]['galleryURL'][0] except: ItemPicture = "" ItemName = ItemsList[Item]['title'][0] #Display stuff sys.stdout.write("\rSearching %d" % Item + " of %d" % TotalCount + " " + "Minutes Remainging: %.2f" % ExpectedTimeRemaining + " " + str(ItemTitle) + " ") sys.stdout.flush() #Calculating Endtime of listing ItemEndTime = ItemsList[Item]['listingInfo'][0]['endTime'][0] Year = int(ItemEndTime[0:4]) Month = int(ItemEndTime[5:7]) Dayy = int(ItemEndTime[8:10]) Hour = int(ItemEndTime[11:13]) Minute = int(ItemEndTime[14:16]) dt = datetime.datetime(Year, Month, Dayy, Hour, Minute, 0) UnixEndingStamp = time.mktime(dt.timetuple()) if (float(UnixEndingStamp) < time.time()): # Item auction end time has passed print('Auction ended already for: ' + str(ItemURL)) # Get shipping on items where shipping changes for different places if ItemShippingType == 'Calculated' or ItemShippingType == 'CalculatedDomesticFlatInternational' or ItemShippingType == 'FreePickup': ItemShipping, driver = Get.Shipping(ItemURL, driver, ShippingDataBase, WebDriverPath) else: try: ItemShipping = ItemsList[Item]['shippingInfo'][0][ 'shippingServiceCost'][0]['__value__'] except: continue global Lot Prices, FinalSearchName, SearchedItems = Get.AvgPrice( ItemURL, ItemTitle, OutOfCalls, float(ItemPrice) + float(ItemShipping), ItemSearchKeywords, float(UnixEndingStamp), AvgPriceDataBase, ErrorsDataBase, UPCDataBase, ImageURL=ItemPicture) if ('Multi Item Auction Found' in FinalSearchName): Info = [ float(ItemPrice) + float(ItemShipping), str(ItemURL), str(False) ] Lot.append(Info) # Store item info in Lot variable and in GUI Logs.Write("Found Lot Item: " + str(Info)) AddToGUI(ItemName, FinalSearchName, str(float(ItemPrice) + float(ItemShipping)), "", ItemPicture, ItemURL, []) if (FinalSearchName == None or ItemTitle == None): # Issues getting specific item names print("Error: 24, None type") print(FinalSearchName) print(ItemTitle) print(ItemURL) Logs.Write("Error: 24, None type " + str(FinalSearchName) + " " + str(ItemTitle) + " " + str(ItemURL) + " " + str(ItemPrice) + " " + str(ItemShipping)) continue if (Prices == -2): #Out of calls OutOfCalls = 1 continue if Prices == -1 or Prices == None: # Error finding avg price continue if ItemSearchKeywords in SpecificProductSearch: # If item needs to be evaluated by Specific Product Search global SpecificProductDiscount SearchingForDiscount = SpecificProductDiscount # Use Specific Product discount # If ending soon, and within discount range if (float(Prices) * SearchingForDiscount > float(ItemPrice) + float(ItemShipping)) and UnixEndingStamp < time.time( ) + EndingSoon and ItemURL not in [ ItemInfo[2] for ItemInfo in OutputSpecific ]: OutputSpecific.append([ float(ItemPrice) + float(ItemShipping), float(Prices), str(ItemURL), str(FinalSearchName), str(SearchingForDiscount), str(ItemSearchKeywords) ]) AddToGUI(ItemName, FinalSearchName, str(float(ItemPrice) + float(ItemShipping)), Prices, ItemPicture, ItemURL, SearchedItems) Logs.Write("Found Discounted Specific Search Item" + str([ float(ItemPrice) + float(ItemShipping), float(Prices), str(ItemURL), str(FinalSearchName), str(ItemSearchKeywords) ])) else: # Use normal discount SearchingForDiscount = Discount if (float(Prices) * SearchingForDiscount > float(ItemPrice) + float(ItemShipping)) and UnixEndingStamp < time.time( ) + EndingSoon and ItemURL not in [ ItemInfo[2] for ItemInfo in Output ]: Output.append([ float(ItemPrice) + float(ItemShipping), float(Prices), str(ItemURL), str(FinalSearchName), str(SearchingForDiscount), str(ItemSearchKeywords) ]) AddToGUI(ItemName, FinalSearchName, str(float(ItemPrice) + float(ItemShipping)), Prices, ItemPicture, ItemURL, SearchedItems) Logs.Write("Found Discounted Item" + str([ float(ItemPrice) + float(ItemShipping), float(Prices), str(ItemURL), str(FinalSearchName), str(ItemSearchKeywords) ])) try: driver.Quit() # Close driver after complete except: print('drive.Quit Failed')