Subversion Repositories SmartDukaan

Rev

Rev 19686 | Blame | Compare with Previous | Last modification | View Log | RSS feed

import pymongo

local_mongo = None

CATEGORY_MAP = {10018:'Carrying Case',10020:'Screen Guard',10014:'Battery'}

def get_mongo_connection(host='localhost', port=27017):
    global local_mongo
    if local_mongo is None:
        print "Establishing connection %s host and port %d" %(host,port)
        try:
            local_mongo = pymongo.MongoClient(host, port)
        except Exception, e:
            print e
            return None
    return local_mongo


def migrate_content(bulkContentUpload):
    new_entity = list(get_mongo_connection().CONTENT.entity.find({'_id':bulkContentUpload.new_entity_id}))
    if bulkContentUpload.category_id in (10018,10020):
        result = get_mongo_connection().CONTENT.entity.update({'_id':new_entity[0]['_id'],"slides.slideDefinitionID":130073},{"$set":{"slides.$.freeformContent.freeformTexts.0":bulkContentUpload.compatibility.strip()}})
    elif bulkContentUpload.category_id in (10014):
        new_entity = list(get_mongo_connection().CONTENT.entity.find({'_id':1016556}))
        result = get_mongo_connection().CONTENT.entity.find({'_id':new_entity[0]['_id']})
        slides = result[0]['slides']
        for i in slides:
            if i['slideDefinitionID'] == 130066:
                for z in i['features']:
                    if z['featureDefinitionID'] == 120103:
                        z['bullets'][0]['dataObject']['properties']['enumValueID'] = bulkContentUpload.battery_type
                    if z['featureDefinitionID'] == 120104:
                        z['bullets'][0]['dataObject']['properties']['value'] = bulkContentUpload.battery_capacity.strip()
            if i['slideDefinitionID'] == 130067:
                i['freeformContent']['freeformTexts'] = [bulkContentUpload.compatibility.strip()]
                        
        result = get_mongo_connection().CONTENT.entity.update({'_id':new_entity[0]['_id']},{"$set":{'slides':slides}})
    else:
        raise
    return result
                    
        
    
def test():
    return
    new_entity = list(get_mongo_connection().CONTENT.entity.find({'_id':1016556}))
    result = get_mongo_connection().CONTENT.entity.find({'_id':new_entity[0]['_id']})
    slides = result[0]['slides']
    for i in slides:
        if i['slideDefinitionID'] == 130066:
            for z in i['features']:
                if z['featureDefinitionID'] == 120103:
                    z['bullets'][0]['dataObject']['properties']['enumValueID'] = 110117
                if z['featureDefinitionID'] == 120104:
                    z['bullets'][0]['dataObject']['properties']['value'] = "200"
        if i['slideDefinitionID'] == 130067:
            i['freeformContent']['freeformTexts'] = ['new comat text']
    
                    
    get_mongo_connection().CONTENT.entity.update({'_id':new_entity[0]['_id']},{"$set":{'slides':slides}})
                    
        
    
    

def getPageTitle(brand, modelName, modelNumber):
    if modelName is None or modelName.strip()=="":
        return ""
    else:
        titleString = brand + " " + modelName  + " " + modelNumber +" Price in India | Specifications, Features and Reviews"
    return titleString

def getMetaDescription(brand, modelName, modelNumber, categoryName):
    if modelName is None or modelName.strip()=="":
        return ""
    template = "Buy {0} {1} {2} at $minPriceItem.getSellingPrice(). All {3} are 100% Original and carry full Manufacturers Warranty since we procure directly from the Brand. Free Next Day Delivery."
    return template.format(brand, modelName, modelNumber, categoryName)
        


if __name__ == '__main__':
    test()