Subversion Repositories SmartDukaan

Rev

Rev 19686 | Details | Compare with Previous | 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():
19933 kshitij.so 45
    return
19686 kshitij.so 46
    new_entity = list(get_mongo_connection().CONTENT.entity.find({'_id':1016556}))
47
    result = get_mongo_connection().CONTENT.entity.find({'_id':new_entity[0]['_id']})
48
    slides = result[0]['slides']
49
    for i in slides:
50
        if i['slideDefinitionID'] == 130066:
51
            for z in i['features']:
52
                if z['featureDefinitionID'] == 120103:
53
                    z['bullets'][0]['dataObject']['properties']['enumValueID'] = 110117
54
                if z['featureDefinitionID'] == 120104:
55
                    z['bullets'][0]['dataObject']['properties']['value'] = "200"
56
        if i['slideDefinitionID'] == 130067:
57
            i['freeformContent']['freeformTexts'] = ['new comat text']
58
 
59
 
60
    get_mongo_connection().CONTENT.entity.update({'_id':new_entity[0]['_id']},{"$set":{'slides':slides}})
61
 
62
 
63
 
64
 
65
 
66
def getPageTitle(brand, modelName, modelNumber):
67
    if modelName is None or modelName.strip()=="":
68
        return ""
69
    else:
70
        titleString = brand + " " + modelName  + " " + modelNumber +" Price in India | Specifications, Features and Reviews"
71
    return titleString
72
 
73
def getMetaDescription(brand, modelName, modelNumber, categoryName):
74
    if modelName is None or modelName.strip()=="":
75
        return ""
76
    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."
77
    return template.format(brand, modelName, modelNumber, categoryName)
78
 
79
 
80
 
81
if __name__ == '__main__':
82
    test()