Exemplo n.º 1
0
def MakeListing():

    type = str(request.args['type'])
    terminatingprice = float(request.args['termprice'])
    status = str(request.args['status'])
    startingprice = float(request.args['startingprice'])
    seller = str(request.args['seller'])
    expirationdate = str(request.args['expirationdate'])

    productid = int(request.args['id'])
    drinkname = str(request.args['drinkname'])
    drinkbrand = str(request.args['drinkbrand'])
    volume = str(request.args['volume'])
    alcoholtype = str(request.args['alcoholtype'])
    alcoholpercentage = str(request.args['alcoholpercentage'])
    countryoforigin = str(request.args['countryoforigin'])
    description = str(request.args['description'])

    product = {
        "_id": productid,
        "DrinkName": drinkname,
        "DrinkBrand": drinkbrand,
        "AlcoholType": alcoholtype,
        "AlcoholPercentage": alcoholpercentage,
        "Volume": volume,
        "CountryOfOrigin": countryoforigin,
        "Description": description
    }

    db.ProductCollection.insert_one(product)
    listing = Listing(type, terminatingprice, drinkname, seller, startingprice,
                      expirationdate, status)
    listing.insertMongodb()
Exemplo n.º 2
0
def createObjects(driver):
    print("Starting to fetch...")
    time.sleep(2)
    driver.execute_script("window.scrollTo(0, 1000);")
    time.sleep(2)
    my_listings = []
    itemcards = driver.find_elements_by_class_name("ffXkEX")

    for itemcard in itemcards:
        hrefs = itemcard.find_elements_by_class_name("kvbvf")

        for href in hrefs:
            containers = href.find_elements_by_class_name("joQnVa")

            for container in containers:
                cards = container.find_elements_by_class_name("hpjVjR")

                for card in cards:
                    boxes = card.find_elements_by_class_name("dADjlv")
                    prices = card.find_elements_by_class_name("kbnIAg")

                    for price in prices:
                        theprice = price.find_element_by_class_name(
                            "gSgzGm").get_attribute("innerHTML")
                    for box in boxes:
                        listings = box.find_elements_by_tag_name("img")
                        for listing in listings:
                            listingobject = Listing(
                                listing.get_attribute("title"), theprice,
                                listing.get_attribute("src"),
                                listing.get_attribute("alt"))
                            my_listings.append(listingobject)
    print("Fetch finished")
    print("Printing Objects...")
    printObjects(my_listings)
Exemplo n.º 3
0
    def __matchListings(self, listings_strings):
        """ Attempt to match listings to products.
        
        For each listing, go through all of the (manufacturer, model_regex) pairs
        (which correspond to products), and, if the manufacturer matches, check if
        the model_regex returns a match when applied to the listing title. If not,
        move onto the next pair. If it does, check if the (manufacturer, model_regex)
        pair corresponds to a unique product. Most of the time, it will.
        
        However, there are a few cases where multiple products have the same
        manufacturer and model. In that case, the "family" field must be used to
        differentiate the products. In this case, we check the listing to see
        which family is being sold. We don't check for the family in any other 
        case, as the model and manufacturer is normally enough.
        
        When we find a match, we continue checking the remaining products to see
        if the listing will match any others. If it does, we throw away the match,
        and we don't match the listing to any product at all. This has the useful
        side effect of eliminating the majority of listings selling items such
        as bags or batteries for a range of models, as those listings list many
        different models, which causes us to throw away the match. """

        for listing_string in listings_strings:
            """ We load into an OrderedDict to preserve the ordering of the fields when
            we print back to JSON. This is not strictly necessary, but it makes it nicer
            for people to viewing the results file to read. """
            listing = Listing(
                json.loads(listing_string, object_pairs_hook=OrderedDict))

            product_matched = None

            try:
                for manufacturer, model_regex in self.__manufacturer_model_pairs:
                    if manufacturer == listing.manufacturer and model_regex.search(
                            listing.title):
                        if product_matched != None:
                            raise MultipleProductsMatchedException
                        else:
                            product_set = self.__product_dict[(manufacturer,
                                                               model_regex)]
                            """ If there's only one product matching this (manufacturer,
                            model_regex) pair, then match the listing to it. Otherwise,
                            we will need to look at the product families to see which
                            one matches. """
                            if len(product_set) == 1:
                                """ Weird syntax for assigning the one element in
                                product_set to product_matched. """
                                product_matched, = product_set
                            else:
                                for product in product_set:
                                    if product.family != "" and product.family in listing.title:
                                        if product_matched != None:
                                            raise MultipleProductsMatchedException
                                        product_matched = product
            except MultipleProductsMatchedException:
                product_matched = None

            if product_matched != None:
                self.__product_listing_dict[product_matched].append(listing)
Exemplo n.º 4
0
    def __init__(self, parent ):
        #tk.Frame.__init__( self, parent )
        super().__init__( parent )
        self.parent = parent

        self.hide_dot_files_folders = True
        self.separate_dirs_n_files = True

        self.widget_list = Listing( self )
        self.widget_commandBar = CommandBar( self )

        self.widget_list.grid( row=0, sticky='nesw' )
        self.widget_commandBar.grid( row=1, sticky='nesw' )

        self.default_directory = os.path.expanduser("~/")
        self.current_working_directory = self.default_directory
        self.navigate_to_absolute_path( self.current_working_directory )

        self.widget_list.focus()
    def test_Product_From_Sortable_Challenge(self):
        """
        Tests the first Listing entry from the sortable challenge, namely:
        "title":"Fujifilm FinePix REAL 3D W3 10 MP Digital Camera\
 with Dual 3x Optical Zoom Lenses (Black)",
        "manufacturer":"Fujifilm Canada",
        "currency":"CAD",
        "price":"499.99"
        We test if the Listing is correctly initiated, if all the
        getters work properly, the string representation is right
        and the JSON representation is right.
        """
        title = "Fujifilm FinePix REAL 3D W3 10 MP Digital Camera\
 with Dual 3x Optical Zoom Lenses (Black)"
        manufacturer = "Fujifilm Canada"
        currency = "CAD"
        price = "499.99"
        stringRep = """Title: Fujifilm FinePix REAL 3D W3 10 MP Digital Camera\
 with Dual 3x Optical Zoom Lenses (Black)
Manufacturer: Fujifilm Canada
Currency: CAD
Price: 499.99"""
        jsonRep = """{"title":"Fujifilm FinePix REAL 3D W3 10 MP Digital Camera with Dual 3x Optical Zoom Lenses (Black)","manufacturer":"Fujifilm Canada","currency":"CAD","price":"499.99"}"""
        try:
            testListing = Listing(title,manufacturer,currency,price)
        except:
            self.fail("Could not instanciate valid Listing")
        self.assertEqual(title,testListing.getTitle(),
                         "The title was not stored properly")
        self.assertEqual(manufacturer,testListing.getManufacturer(),
                         "The manufacturer was not stored properly")
        self.assertEqual(currency,testListing.getCurrency(),
                         "The Currency was not stored properly")
        self.assertEqual(price,testListing.getPrice(),
                         "The price was not stored properly")
        self.assertEqual(stringRep, str(testListing),
                         "The string representation was not correct")
        self.assertEqual(json.loads(jsonRep),json.loads(testListing.toJSON()),
                         "The JSON representation was not correct")
Exemplo n.º 6
0
class Explorer( tk.Frame ):
    """
    Allows the user to navigate the file tree.
    Uses two widgets to convey this: Explorer and Listing.
    Explorer controls the file navigation.
    """
    def __init__(self, parent ):
        #tk.Frame.__init__( self, parent )
        super().__init__( parent )
        self.parent = parent

        self.hide_dot_files_folders = True
        self.separate_dirs_n_files = True

        self.widget_list = Listing( self )
        self.widget_commandBar = CommandBar( self )

        self.widget_list.grid( row=0, sticky='nesw' )
        self.widget_commandBar.grid( row=1, sticky='nesw' )

        self.default_directory = os.path.expanduser("~/")
        self.current_working_directory = self.default_directory
        self.navigate_to_absolute_path( self.current_working_directory )

        self.widget_list.focus()


    def __getstate__( self ):
        # have a way to save the default directory
        #return pickle.dumps( self.contents ) + pickle.dumps( self.widget_list ) + pickle.dumps( self.widget_commandBar )
        return None

    def __setstate__( self, item ):
        return None

    # post grid row column
    def pgrc_configure(self):
        self.rowconfigure(0, weight=1)
        self.columnconfigure('all', weight=1)

    def navigate_to_absolute_path( self, absolute_path ):
        """Expects absolute path.
        Fills in the listing widget with the contents of the directory and colors some of the entries light gray."""
        if os.path.isdir( absolute_path ):
            os.chdir( absolute_path )
            self.current_working_directory = absolute_path
            self.contents = os.listdir( self.current_working_directory )
            if self.hide_dot_files_folders:
                self.contents = list( filter( lambda y: not y.startswith("."), self.contents ) )
            self.widget_list.replace_contents( self.contents )
            self.color_directories()
    def color_directories(self):
        for index, entry in enumerate( self.widget_list.get( 0, tk.END ) ):
            if os.path.isdir( os.path.join( self.current_working_directory, entry ) ):
                self.widget_list.itemconfig( index, fg='dark blue' )

    def primary( self, items ):
        if len( items ) == 1:
            newpath = os.path.join( self.current_working_directory, items[0] )
            if os.path.isdir( newpath ):
                self.__folder_primary( newpath )
            else:
                self.__file_primary( newpath )
        return None

    def secondary( self, items ):
        print( items )

    def alt_up( self, event ):
        head = os.path.dirname( self.current_working_directory )
        self.navigate_to_absolute_path( head )
        return None

    def refresh_list(self):
        self.navigate_to_absolute_path( self.current_working_directory )

    def filter_list(self, string):
        pattern = re.compile(string)
        contents = self.contents[:]
        contents = filter(lambda y: re.match(pattern, y), contents)
        self.widget_list.replace_contents(contents)
        self.color_directories()
        print("replace!")
        return None
    
    def __folder_primary( self, abs_path ):
        self.parent.status_last_command( "cd " + str(abs_path) )
        #print( "cd", path)
        self.navigate_to_absolute_path( abs_path )
        return None

    def __file_primary( self, path ):
        if sys.platform == "linux" or sys.platform == "linux2":
            #os.system( "xdg-open " + path )
            os.popen( "xdg-open " + path.replace(" ","\ ") )
        elif sys.platform == "win32":
            os.popen( "start " + path.replace(" ","\ ") )
        elif sys.platform == "darwin":
            os.popen( "" + path.replace(" ","\ ") )
        return None