Subversion Repositories SmartDukaan

Rev

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

Rev 18615 Rev 19136
Line 1... Line 1...
1
from elasticsearch import Elasticsearch
1
from elasticsearch import Elasticsearch
2
from dtr.utils.utils import get_mongo_connection
2
from dtr.utils.utils import get_mongo_connection
3
import optparse
3
import optparse
-
 
4
from pymongo import DESCENDING
4
 
5
 
5
parser = optparse.OptionParser()
6
parser = optparse.OptionParser()
6
parser.add_option("-m", "--m", dest="mongoHost",
7
parser.add_option("-m", "--m", dest="mongoHost",
7
                      default="localhost",
8
                      default="localhost",
8
                      type="string", help="The HOST where the mongo server is running",
9
                      type="string", help="The HOST where the mongo server is running",
Line 24... Line 25...
24
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}])
25
xstr = lambda s: s or ""
26
xstr = lambda s: s or ""
26
 
27
 
27
class __SkuInfo:
28
class __SkuInfo:
28
    
29
    
29
    def __init__(self, id, title, category_id, subCategoryId, subCategory):
30
    def __init__(self, id, title, category_id, subCategoryId, subCategory, dealPoints):
30
        self.id = id
31
        self.id = id
31
        self.title = title
32
        self.title = title
32
        self.category_id = category_id
33
        self.category_id = category_id
33
        self.subCategoryId = subCategoryId
34
        self.subCategoryId = subCategoryId
34
        self.subCategory = subCategory
35
        self.subCategory = subCategory
-
 
36
        self.dealPoints = dealPoints
35
 
37
 
36
def main():
38
def main():
37
    added = []
39
    added = []
38
    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}}))
39
    for item in items:
41
    for item in items:
40
        if item['skuBundleId'] in added:
42
        if item['skuBundleId'] in added:
41
            continue
43
            continue
-
 
44
        deal_obj = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':item['skuBundleId']}).sort([('totalPoints',DESCENDING)]))
-
 
45
        if len(deal_obj) == 0:
-
 
46
            dealPoints = 0
-
 
47
        else:
-
 
48
            dealPoints = deal_obj[0]['totalPoints']
42
        title = xstr(item['brand'])+" "+xstr(item['model_name'])
49
        title = xstr(item['brand'])+" "+xstr(item['model_name'])
43
        s_info = __SkuInfo(int(item['skuBundleId']),title,int(item['category_id']),int(item['subCategoryId']),item['subCategory'])
50
        s_info = __SkuInfo(int(item['skuBundleId']),title,int(item['category_id']),int(item['subCategoryId']),item['subCategory'], dealPoints)
44
        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__)
45
        added.append(int(item['skuBundleId']))
52
        added.append(int(item['skuBundleId']))
46
 
53
 
47
def validateListings():
54
def validateListings():
48
    offset , limit = 0, 100
55
    offset , limit = 0, 100