示例#1
0
def main():
    try:
        db = connect_to_mongo()
        name = 'admin'
        collection = 'tops'

        tops = db[collection]
        print "Number of items to process: %s" % tops.count()
        for idx, d in enumerate(tops.find()[:]):
            top_id = d['_id']
            img_url = str(d['img_url'])

            # image names may be missing http:// in front
            if img_url.startswith("//"):
                img_url = "http://" + img_url[2:]

            if not img_url.startswith("http://"):
                img_url = "http://" + img_url

            print "%d: Processing id %s with %s" %(idx, top_id, img_url)

            try:
                item_color = ItemColor(str(top_id), img_url)
                item_color.detect_colors()

                # update field for id with color
                tops.update({"_id": top_id}, {"$set": {"colors": item_color.rgb_colors}})
            except Exception, e:
                print '[ERROR] %s' % (e)
                continue

        print "Count of items with no colors: %s" % tops.find({"colors": "_not_available_"}).count()
        print "Processing complete"
示例#2
0
    def fetch_all_porducts(db=None):
        if not db:
            db = connect_to_mongo() 
        prds = db['tops'].find({})
        import pdb
        pdb.set_trace()   
        for prd in prds:

            print prd            
示例#3
0
    def fetch_all_porducts(db=None):
        if not db:
            db = connect_to_mongo()
        prds = db['tops'].find({})
        import pdb
        pdb.set_trace()
        for prd in prds:

            print prd
示例#4
0
def reset():
    try:
        db = connect_to_mongo()
        collection = 'tops'

        tops = db[collection]
        for d in tops.find()[:]:
            top_id = d['_id']
            tops.update({"_id": top_id}, {"$set": {"colors": "_not_available_"}})

    finally:
        disconnect_from_mongo(db)
示例#5
0
def reset():
    try:
        db = connect_to_mongo()
        collection = 'tops'

        tops = db[collection]
        for d in tops.find()[:]:
            top_id = d['_id']
            tops.update({"_id": top_id},
                        {"$set": {
                            "colors": "_not_available_"
                        }})

    finally:
        disconnect_from_mongo(db)
示例#6
0
def main():
    try:
        db = connect_to_mongo()
        name = 'admin'
        collection = 'tops'

        tops = db[collection]
        print "Number of items to process: %s" % tops.count()
        for idx, d in enumerate(tops.find()[:]):
            top_id = d['_id']
            img_url = str(d['img_url'])

            # image names may be missing http:// in front
            if img_url.startswith("//"):
                img_url = "http://" + img_url[2:]

            if not img_url.startswith("http://"):
                img_url = "http://" + img_url

            print "%d: Processing id %s with %s" % (idx, top_id, img_url)

            try:
                item_color = ItemColor(str(top_id), img_url)
                item_color.detect_colors()

                # update field for id with color
                tops.update({"_id": top_id},
                            {"$set": {
                                "colors": item_color.rgb_colors
                            }})
            except Exception, e:
                print "%s - img_url = %s" % (e, img_url)
                logging.warning("%s - img_url = %s" % (e, img_url))
                if (item_color.palette is not None):
                    print "%s: %s" % (img_url, str(item_color.palette))
                    logging.warning("%s: %s" %
                                    (img_url, str(item_color.palette)))
                continue

        print "Count of items with no colors: %s" % tops.find({
            "colors":
            "_not_available_"
        }).count()
        print "Processing complete"
示例#7
0
        price = min(price)
    else:
        price = max(price)
    
    purchase = user_purchase(user['_id'],
                             product['_id'],
                             price
                            )
    purchase.populate_fuzzy_ratings(color_s, complexity_s, size_s)
    purchase.price = price
    entry = purchase.to_dict()
    db['purchase_history'].insert(entry)
    return purchase

    def fetch_all_porducts(db=None):
        if not db:
            db = connect_to_mongo() 
        prds = db['tops'].find({})
        import pdb
        pdb.set_trace()   
        for prd in prds:

            print prd            


if __name__ == '__main__':
    db = connect_to_mongo()
    name = 'admin'
    user = setup_user(db, name)
    add_purchase(db['tops'], db['user'].find_one({}), db['tops'].find_one({}))
示例#8
0
    func = lambda p: float(p.split(' ')[0][1:]) if p else -1
    price = map(func, price)
    if min(price) > 0:
        price = min(price)
    else:
        price = max(price)

    purchase = user_purchase(user['_id'], product['_id'], price)
    purchase.populate_fuzzy_ratings(color_s, complexity_s, size_s)
    purchase.price = price
    entry = purchase.to_dict()
    db['purchase_history'].insert(entry)
    return purchase

    def fetch_all_porducts(db=None):
        if not db:
            db = connect_to_mongo()
        prds = db['tops'].find({})
        import pdb
        pdb.set_trace()
        for prd in prds:

            print prd


if __name__ == '__main__':
    db = connect_to_mongo()
    name = 'admin'
    user = setup_user(db, name)
    add_purchase(db['tops'], db['user'].find_one({}), db['tops'].find_one({}))
示例#9
0
 def open_spider(self, spider):
     self.db = connect_to_mongo()
示例#10
0
 def open_spider(self, spider):
     self.db = connect_to_mongo()
        categories = self.db['tops'].distinct('category')
        categories = [category for category in categories
                      if category not in self.blacklist_categories]
        return dict(zip(categories, xrange(0,len(categories))))

    def reduce_prices(self, prices):
        func = lambda p: float(p.split(' ')[0][1:]) if p else -1
        price = map(func, prices)
        if min(price) > 0:
            price = min(price)
        else:
            price = max(price)
        return price


db = connect_to_mongo("Tailor")
ann_training = AnnTraining(db)
tops = ann_training.get_tops()
total_brands = ann_training.get_brands()
total_categories = ann_training.get_category()

for top in tops[:]:
    # colors
    colors = top.get('colors') if top.get('colors') != "_not_available_" else None
    try:
        colors = [int(i) for i in colors[1:len(colors) - 1].split(",")]
        colors = Color(rgb=(colors[0] / 255.0, colors[1] / 255.0, colors[2] / 255.0))
    except Exception, e:
        print "[ERROR] %s has failed to produce a color. %s" % (top['_id'], e)
        colors = None