Subversion Repositories SmartDukaan

Rev

Rev 14249 | Rev 15068 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14249 Rev 15067
Line 24... Line 24...
24
                      type="string", help="The HOST where the mongo server is running",
24
                      type="string", help="The HOST where the mongo server is running",
25
                      metavar="HOST")
25
                      metavar="HOST")
26
 
26
 
27
(options, args) = parser.parse_args()
27
(options, args) = parser.parse_args()
28
 
28
 
-
 
29
synonymsMap = {}
-
 
30
modelNameSynonymMap = {}
-
 
31
 
29
 
32
 
30
class __SkuInfo:
33
class __SkuInfo:
31
    
34
    
32
    def __init__(self, id, skuBundleId, brand, model_name, source_product_name, category_id, category, available_price, mrp, in_stock, \
35
    def __init__(self, id, skuBundleId, brand, model_name, source_product_name, category_id, category, available_price, mrp, in_stock, \
33
                 source_id, store, title, thumbnail, priceUpdatedOn):
36
                 source_id, store, title, thumbnail, priceUpdatedOn, brand_synonyms, model_name_synonyms):
34
        self.id = id
37
        self.id = id
35
        self.skuBundleId = skuBundleId
38
        self.skuBundleId = skuBundleId
36
        self.brand = brand
39
        self.brand = brand
37
        self.model_name = model_name
40
        self.model_name = model_name
38
        self.source_product_name = source_product_name
41
        self.source_product_name = source_product_name
Line 44... Line 47...
44
        self.source_id = source_id
47
        self.source_id = source_id
45
        self.store = store
48
        self.store = store
46
        self.title= title
49
        self.title= title
47
        self.thumbnail = thumbnail
50
        self.thumbnail = thumbnail
48
        self.priceUpdatedOn = priceUpdatedOn
51
        self.priceUpdatedOn = priceUpdatedOn
-
 
52
        self.brand_synonyms = brand_synonyms
-
 
53
        self.model_name_synonyms = model_name_synonyms
49
        
54
        
50
        
55
        
51
solr = pysolr.Solr("http://104.200.25.40:8080/solr/", timeout=10)
56
solr = pysolr.Solr("http://104.200.25.40:8080/solr/", timeout=10)
52
 
57
 
53
def pushData():
58
def pushData():
-
 
59
    populateBrandSynonymMap()
-
 
60
    populateModelNameSynonyms
54
    l = []
61
    l = []
55
    catalogMap = {}
62
    catalogMap = {}
56
    items = get_mongo_connection(options.mongoHost).Catalog.MasterData.find({'source_id' : { "$in": SOURCE_MAP.values() } })
63
    items = get_mongo_connection(options.mongoHost).Catalog.MasterData.find({'source_id' : { "$in": SOURCE_MAP.values() } })
57
    print items.count()
64
    print items.count()
58
    for item in items:
65
    for item in items:
59
        title = xstr(item['brand'])+" "+xstr(item['model_name'])
66
        title = xstr(item['brand'])+" "+xstr(item['model_name'])
60
        if not catalogMap.has_key(str(item['skuBundleId'])+" "+title):
67
        if not catalogMap.has_key(str(item['skuBundleId'])+" "+title):
61
            catalogMap[str(item['skuBundleId'])+" "+title] = [title]
68
            catalogMap[str(item['skuBundleId'])+" "+title] = [title]
62
        s_info = __SkuInfo(str(item['_id']),int(item['skuBundleId']),(item['brand']),(item['model_name']),(item['source_product_name']),int(item['category_id']),categoryMap.get(item['category_id']),float(item['available_price']),float(item['mrp']),item['in_stock'], \
69
        s_info = __SkuInfo(str(item['_id']),int(item['skuBundleId']),(item['brand']),(item['model_name']),(item['source_product_name']),int(item['category_id']),categoryMap.get(item['category_id']),float(item['available_price']),float(item['mrp']),item['in_stock'], \
63
                        int(item['source_id']),(item['source']),title,(item['thumbnail']), long(item['priceUpdatedOn']))
70
                        int(item['source_id']),(item['source']),title,(item['thumbnail']), long(item['priceUpdatedOn']), synonymsMap.get(item['brand'].upper()), modelNameSynonymMap.get(item['skuBundleId']))
64
        l.append(s_info.__dict__)
71
        l.append(s_info.__dict__)
65
    solr.add(l)
72
    solr.add(l)
66
    
73
    
67
    autoSuggestList = []
74
    autoSuggestList = []
68
    for v in catalogMap.itervalues():
75
    for v in catalogMap.itervalues():
Line 82... Line 89...
82
        except:
89
        except:
83
            shutil.copy2(filePath, destFilePath)
90
            shutil.copy2(filePath, destFilePath)
84
    
91
    
85
    
92
    
86
 
93
 
-
 
94
def populateBrandSynonymMap(): 
-
 
95
    global synonymsMap
-
 
96
    brand_synonyms = get_mongo_connection(options.mongoHost).Catalog.BrandSynonyms.find()
-
 
97
    for synonym in brand_synonyms:
-
 
98
        synonymsMap[synonym['brand'].upper()] = synonym['synonyms']
-
 
99
 
-
 
100
def populateModelNameSynonyms():
-
 
101
    global modelNameSynonymMap
-
 
102
    model_synonyms = get_mongo_connection(options.mongoHost).Catalog.ModelNameSynonyms.find()
-
 
103
    for synonym in model_synonyms:
-
 
104
        modelNameSynonymMap[synonym['skuBundleId']] = synonym['synonyms'] 
-
 
105
 
87
def get_mongo_connection(host='localhost', port=27017):
106
def get_mongo_connection(host='localhost', port=27017):
88
    global con
107
    global con
89
    if con is None:
108
    if con is None:
90
        print "Establishing connection %s host and port %d" %(host,port)
109
        print "Establishing connection %s host and port %d" %(host,port)
91
        try:
110
        try: