Subversion Repositories SmartDukaan

Rev

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

Rev 19542 Rev 19571
Line 25... Line 25...
25
es = Elasticsearch([{'host': options.elastic_search_host, 'port': options.elastic_search_port}])
25
es = Elasticsearch([{'host': options.elastic_search_host, 'port': options.elastic_search_port}])
26
xstr = lambda s: s or ""
26
xstr = lambda s: s or ""
27
 
27
 
28
class __SkuInfo:
28
class __SkuInfo:
29
    
29
    
30
    def __init__(self, id, title, category_id, subCategoryId, subCategory, dealPoints):
30
    def __init__(self, id, title, category_id, subCategoryId, subCategory, internalRank):
31
        self.id = id
31
        self.id = id
32
        self.title = title
32
        self.title = title
33
        self.category_id = category_id
33
        self.category_id = category_id
34
        self.subCategoryId = subCategoryId
34
        self.subCategoryId = subCategoryId
35
        self.subCategory = subCategory
35
        self.subCategory = subCategory
36
        self.dealPoints = dealPoints
36
        self.internalRank = internalRank
37
 
37
 
38
def main():
38
def main():
39
    added = []
39
    added = []
40
    items = list(get_mongo_connection(host=options.mongoHost).Catalog.MasterData.find({'subCategoryId':{"$in":subCategoryList}}))
40
    items = list(get_mongo_connection(host=options.mongoHost).Catalog.MasterData.find({'subCategoryId':{"$in":subCategoryList}}))
41
    for item in items:
41
    for item in items:
42
        if item['skuBundleId'] in added:
42
        if item['skuBundleId'] in added:
43
            continue
43
            continue
44
        deal_obj = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':item['skuBundleId']}).sort([('totalPoints',DESCENDING)]))
44
        deal_obj = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':item['skuBundleId']}).sort([('totalPoints',DESCENDING)]))
45
        if len(deal_obj) == 0:
45
        if len(deal_obj) == 0:
46
            dealPoints = 0
46
            internalRank = 999999
47
        else:
47
        else:
48
            dealPoints = deal_obj[0]['totalPoints']
48
            internalRank = deal_obj[0]['internalRank']
49
        title = xstr(item['brand'])+" "+xstr(item['model_name'])
49
        title = xstr(item['brand'])+" "+xstr(item['model_name'])
50
        s_info = __SkuInfo(int(item['skuBundleId']),title,int(item['category_id']),int(item['subCategoryId']),item['subCategory'], dealPoints)
50
        s_info = __SkuInfo(int(item['skuBundleId']),title,int(item['category_id']),int(item['subCategoryId']),item['subCategory'], internalRank)
51
        es.index(index='my_index', doc_type='my_type', id=s_info.id,body=s_info.__dict__)
51
        es.index(index='my_index', doc_type='my_type', id=s_info.id,body=s_info.__dict__)
52
        added.append(int(item['skuBundleId']))
52
        added.append(int(item['skuBundleId']))
53
 
53
 
54
def validateListings():
54
def validateListings():
55
    offset , limit = 0, 100
55
    offset , limit = 0, 100