| 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 ASCENDING
|
4 |
from pymongo import DESCENDING
|
| 5 |
|
5 |
|
| 6 |
parser = optparse.OptionParser()
|
6 |
parser = optparse.OptionParser()
|
| 7 |
parser.add_option("-m", "--m", dest="mongoHost",
|
7 |
parser.add_option("-m", "--m", dest="mongoHost",
|
| 8 |
default="localhost",
|
8 |
default="localhost",
|
| 9 |
type="string", help="The HOST where the mongo server is running",
|
9 |
type="string", help="The HOST where the mongo server is running",
|
| 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, internalRank):
|
30 |
def __init__(self, id, title, category_id, subCategoryId, subCategory, dealRankPoints):
|
| 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.internalRank = internalRank
|
36 |
self.dealRankPoints = dealRankPoints
|
| 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'],'internalRank':{"$gt":0}}).sort([('internalRank',ASCENDING)]))
|
44 |
deal_obj = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':item['skuBundleId'],'dealRankPoints':{"$gt":0}}).sort([('internalRank', DESCENDING)]))
|
| 45 |
if len(deal_obj) == 0:
|
45 |
if len(deal_obj) == 0:
|
| 46 |
internalRank = 999999
|
46 |
dealRankPoints = 0
|
| 47 |
else:
|
47 |
else:
|
| 48 |
internalRank = deal_obj[0]['internalRank']
|
48 |
dealRankPoints = deal_obj[0]['dealRankPoints']
|
| 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'], internalRank)
|
50 |
s_info = __SkuInfo(int(item['skuBundleId']),title,int(item['category_id']),int(item['subCategoryId']),item['subCategory'], dealRankPoints)
|
| 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
|