Subversion Repositories SmartDukaan

Rev

Rev 19933 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
19686 kshitij.so 1
import pymongo
2
 
3
local_mongo = None
4
 
5
CATEGORY_MAP = {10018:'Carrying Case',10020:'Screen Guard',10014:'Battery'}
6
 
7
def get_mongo_connection(host='localhost', port=27017):
8
    global local_mongo
9
    if local_mongo is None:
10
        print "Establishing connection %s host and port %d" %(host,port)
11
        try:
12
            local_mongo = pymongo.MongoClient(host, port)
13
        except Exception, e:
14
            print e
15
            return None
16
    return local_mongo
17
 
18
 
19
def migrate_content(bulkContentUpload):
20
    new_entity = list(get_mongo_connection().CONTENT.entity.find({'_id':bulkContentUpload.new_entity_id}))
21
    if bulkContentUpload.category_id in (10018,10020):
22
        result = get_mongo_connection().CONTENT.entity.update({'_id':new_entity[0]['_id'],"slides.slideDefinitionID":130073},{"$set":{"slides.$.freeformContent.freeformTexts.0":bulkContentUpload.compatibility.strip()}})
23
    elif bulkContentUpload.category_id in (10014):
24
        new_entity = list(get_mongo_connection().CONTENT.entity.find({'_id':1016556}))
25
        result = get_mongo_connection().CONTENT.entity.find({'_id':new_entity[0]['_id']})
26
        slides = result[0]['slides']
27
        for i in slides:
28
            if i['slideDefinitionID'] == 130066:
29
                for z in i['features']:
30
                    if z['featureDefinitionID'] == 120103:
31
                        z['bullets'][0]['dataObject']['properties']['enumValueID'] = bulkContentUpload.battery_type
32
                    if z['featureDefinitionID'] == 120104:
33
                        z['bullets'][0]['dataObject']['properties']['value'] = bulkContentUpload.battery_capacity.strip()
34
            if i['slideDefinitionID'] == 130067:
35
                i['freeformContent']['freeformTexts'] = [bulkContentUpload.compatibility.strip()]
36
 
37
        result = get_mongo_connection().CONTENT.entity.update({'_id':new_entity[0]['_id']},{"$set":{'slides':slides}})
38
    else:
39
        raise
40
    return result
41
 
42
 
43
 
44
def test():
45
    new_entity = list(get_mongo_connection().CONTENT.entity.find({'_id':1016556}))
46
    result = get_mongo_connection().CONTENT.entity.find({'_id':new_entity[0]['_id']})
47
    slides = result[0]['slides']
48
    for i in slides:
49
        if i['slideDefinitionID'] == 130066:
50
            for z in i['features']:
51
                if z['featureDefinitionID'] == 120103:
52
                    z['bullets'][0]['dataObject']['properties']['enumValueID'] = 110117
53
                if z['featureDefinitionID'] == 120104:
54
                    z['bullets'][0]['dataObject']['properties']['value'] = "200"
55
        if i['slideDefinitionID'] == 130067:
56
            i['freeformContent']['freeformTexts'] = ['new comat text']
57
 
58
 
59
    get_mongo_connection().CONTENT.entity.update({'_id':new_entity[0]['_id']},{"$set":{'slides':slides}})
60
 
61
 
62
 
63
 
64
 
65
def getPageTitle(brand, modelName, modelNumber):
66
    if modelName is None or modelName.strip()=="":
67
        return ""
68
    else:
69
        titleString = brand + " " + modelName  + " " + modelNumber +" Price in India | Specifications, Features and Reviews"
70
    return titleString
71
 
72
def getMetaDescription(brand, modelName, modelNumber, categoryName):
73
    if modelName is None or modelName.strip()=="":
74
        return ""
75
    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."
76
    return template.format(brand, modelName, modelNumber, categoryName)
77
 
78
 
79
 
80
if __name__ == '__main__':
81
    test()