Subversion Repositories SmartDukaan

Rev

Rev 19933 | Details | Compare with Previous | Last modification | View Log | RSS feed

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