| Line 2... |
Line 2... |
| 2 |
import xlwt
|
2 |
import xlwt
|
| 3 |
from datetime import datetime
|
3 |
from datetime import datetime
|
| 4 |
from email.mime.multipart import MIMEMultipart
|
4 |
from email.mime.multipart import MIMEMultipart
|
| 5 |
import email.encoders
|
5 |
import email.encoders
|
| 6 |
import smtplib
|
6 |
import smtplib
|
| 7 |
from dtr.utils.utils import getCashBack
|
- |
|
| 8 |
from dtr.storage.MemCache import MemCache
|
- |
|
| 9 |
|
- |
|
| 10 |
|
7 |
|
| 11 |
con = None
|
8 |
con = None
|
| 12 |
|
9 |
|
| 13 |
statusMap = {1:'Active',2:'EOL',3:'In Process',4:'Exclusive'}
|
10 |
statusMap = {1:'Active',2:'EOL',3:'In Process',4:'Exclusive'}
|
| 14 |
mc = MemCache("127.0.0.1")
|
- |
|
| 15 |
|
11 |
|
| 16 |
class __SkuInfo:
|
12 |
class __SkuInfo:
|
| 17 |
|
13 |
|
| 18 |
def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
|
14 |
def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
|
| 19 |
maxDiscount, discountType, dp, nlcPoints, bestSellerPoints, totalPoints,in_stock,maxprice,showDeal, catalogBestSellerPoints, \
|
15 |
maxDiscount, discountType, dp, nlcPoints, bestSellerPoints, totalPoints,in_stock,maxprice,showDeal, catalogBestSellerPoints):
|
| 20 |
showDealOld):
|
- |
|
| 21 |
self._id = _id
|
16 |
self._id = _id
|
| 22 |
self.skuBundleId = skuBundleId
|
17 |
self.skuBundleId = skuBundleId
|
| 23 |
self.category_id = category_id
|
18 |
self.category_id = category_id
|
| 24 |
self.mrp = mrp
|
19 |
self.mrp = mrp
|
| 25 |
self.available_price = available_price
|
20 |
self.available_price = available_price
|
| Line 36... |
Line 31... |
| 36 |
self.bestSellerPoints = bestSellerPoints
|
31 |
self.bestSellerPoints = bestSellerPoints
|
| 37 |
self.totalPoints = totalPoints
|
32 |
self.totalPoints = totalPoints
|
| 38 |
self.in_stock = in_stock
|
33 |
self.in_stock = in_stock
|
| 39 |
self.maxprice = maxprice
|
34 |
self.maxprice = maxprice
|
| 40 |
self.showDeal = showDeal
|
35 |
self.showDeal = showDeal
|
| 41 |
self.catalogBestSellerPoints = catalogBestSellerPoints
|
36 |
self.catalogBestSellerPoints = catalogBestSellerPoints
|
| 42 |
self.showDealOld = showDealOld
|
- |
|
| 43 |
|
37 |
|
| 44 |
def get_mongo_connection(host='localhost', port=27017):
|
38 |
def get_mongo_connection(host='localhost', port=27017):
|
| 45 |
global con
|
39 |
global con
|
| 46 |
if con is None:
|
40 |
if con is None:
|
| 47 |
print "Establishing connection %s host and port %d" %(host,port)
|
41 |
print "Establishing connection %s host and port %d" %(host,port)
|
| Line 57... |
Line 51... |
| 57 |
data = get_mongo_connection().Catalog.Deals.find().sort([('totalPoints',pymongo.DESCENDING)])
|
51 |
data = get_mongo_connection().Catalog.Deals.find().sort([('totalPoints',pymongo.DESCENDING)])
|
| 58 |
print data.count()
|
52 |
print data.count()
|
| 59 |
for x in data:
|
53 |
for x in data:
|
| 60 |
s_info = __SkuInfo(x['_id'], x['skuBundleId'], x['category_id'],x['mrp'],x['available_price'],x['source_id'],x['rank'],x['maxNlc'], \
|
54 |
s_info = __SkuInfo(x['_id'], x['skuBundleId'], x['category_id'],x['mrp'],x['available_price'],x['source_id'],x['rank'],x['maxNlc'], \
|
| 61 |
x['minNlc'], x['schemeAmount'],x['minDiscount'],x['maxDiscount'],x['discountType'],x['dp'],x['nlcPoints'],x['bestSellerPoints'], \
|
55 |
x['minNlc'], x['schemeAmount'],x['minDiscount'],x['maxDiscount'],x['discountType'],x['dp'],x['nlcPoints'],x['bestSellerPoints'], \
|
| 62 |
x['totalPoints'],x['in_stock'],x['maxprice'],x['showDeal'],x['catalogBestSellerPoints'],x['showDealOld'])
|
56 |
x['totalPoints'],x['in_stock'],x['maxprice'],x['showDeal'],x['catalogBestSellerPoints'])
|
| 63 |
p.append(s_info)
|
57 |
p.append(s_info)
|
| 64 |
|
58 |
|
| 65 |
wbk = xlwt.Workbook()
|
59 |
wbk = xlwt.Workbook()
|
| 66 |
sheet = wbk.add_sheet('Deals')
|
60 |
sheet = wbk.add_sheet('Deals')
|
| 67 |
xstr = lambda s: s or ""
|
61 |
xstr = lambda s: s or ""
|
| Line 82... |
Line 76... |
| 82 |
sheet.write(0, 8, "MarketPlace Identifier", heading_xf)
|
76 |
sheet.write(0, 8, "MarketPlace Identifier", heading_xf)
|
| 83 |
sheet.write(0, 9, "MarketPlace Secondary Identifier", heading_xf)
|
77 |
sheet.write(0, 9, "MarketPlace Secondary Identifier", heading_xf)
|
| 84 |
sheet.write(0, 10, "Product Name (Marketplace)", heading_xf)
|
78 |
sheet.write(0, 10, "Product Name (Marketplace)", heading_xf)
|
| 85 |
sheet.write(0, 11, "Url", heading_xf)
|
79 |
sheet.write(0, 11, "Url", heading_xf)
|
| 86 |
sheet.write(0, 12, "Price", heading_xf)
|
80 |
sheet.write(0, 12, "Price", heading_xf)
|
| 87 |
sheet.write(0, 13, "After Cashback", heading_xf)
|
- |
|
| 88 |
sheet.write(0, 14, "Mrp", heading_xf)
|
81 |
sheet.write(0, 13, "Mrp", heading_xf)
|
| 89 |
sheet.write(0, 15, "DP", heading_xf)
|
82 |
sheet.write(0, 14, "DP", heading_xf)
|
| 90 |
sheet.write(0, 16, "Scheme Amount", heading_xf)
|
83 |
sheet.write(0, 15, "Scheme Amount", heading_xf)
|
| 91 |
sheet.write(0, 17, "Discount Type", heading_xf)
|
84 |
sheet.write(0, 16, "Discount Type", heading_xf)
|
| 92 |
sheet.write(0, 18, "Min Discount", heading_xf)
|
85 |
sheet.write(0, 17, "Min Discount", heading_xf)
|
| 93 |
sheet.write(0, 19, "Max Discount", heading_xf)
|
86 |
sheet.write(0, 18, "Max Discount", heading_xf)
|
| 94 |
sheet.write(0, 20, "Max Nlc", heading_xf)
|
87 |
sheet.write(0, 19, "Max Nlc", heading_xf)
|
| 95 |
sheet.write(0, 21, "Min Nlc", heading_xf)
|
88 |
sheet.write(0, 20, "Min Nlc", heading_xf)
|
| 96 |
sheet.write(0, 22, "Max Price", heading_xf)
|
89 |
sheet.write(0, 21, "Max Price", heading_xf)
|
| 97 |
sheet.write(0, 23, "Rank", heading_xf)
|
90 |
sheet.write(0, 22, "Rank", heading_xf)
|
| 98 |
sheet.write(0, 24, "Nlc Points", heading_xf)
|
91 |
sheet.write(0, 23, "Nlc Points", heading_xf)
|
| 99 |
sheet.write(0, 25, "Best Seller Points", heading_xf)
|
92 |
sheet.write(0, 24, "Best Seller Points", heading_xf)
|
| 100 |
sheet.write(0, 26, "Catalog Best Seller Points", heading_xf)
|
93 |
sheet.write(0, 25, "Catalog Best Seller Points", heading_xf)
|
| 101 |
sheet.write(0, 27, "Total Points", heading_xf)
|
94 |
sheet.write(0, 26, "Total Points", heading_xf)
|
| 102 |
sheet.write(0, 28, "Show Deals", heading_xf)
|
95 |
sheet.write(0, 27, "Show Deals", heading_xf)
|
| 103 |
sheet.write(0, 29, "Show Deals Old", heading_xf)
|
- |
|
| 104 |
|
96 |
|
| 105 |
it = 1
|
97 |
it = 1
|
| 106 |
for x in p:
|
98 |
for x in p:
|
| 107 |
y = list(get_mongo_connection().Catalog.MasterData.find({'_id':x._id}))
|
99 |
y = list(get_mongo_connection().Catalog.MasterData.find({'_id':x._id}))
|
| 108 |
sheet.write(it, 0, x._id)
|
100 |
sheet.write(it, 0, x._id)
|
| Line 123... |
Line 115... |
| 123 |
sheet.write(it, 8, y[0]['identifier'])
|
115 |
sheet.write(it, 8, y[0]['identifier'])
|
| 124 |
sheet.write(it, 9, y[0]['secondaryIdentifier'])
|
116 |
sheet.write(it, 9, y[0]['secondaryIdentifier'])
|
| 125 |
sheet.write(it, 10, y[0]['source_product_name'])
|
117 |
sheet.write(it, 10, y[0]['source_product_name'])
|
| 126 |
sheet.write(it, 11, y[0]['url'])
|
118 |
sheet.write(it, 11, y[0]['url'])
|
| 127 |
sheet.write(it, 12, y[0]['available_price'])
|
119 |
sheet.write(it, 12, y[0]['available_price'])
|
| 128 |
cashBack = getCashBack(x._id, x.source_id, x.category_id, mc, 'localhost')
|
- |
|
| 129 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
- |
|
| 130 |
pass
|
- |
|
| 131 |
else:
|
- |
|
| 132 |
if cashBack['cash_back_type'] ==1:
|
- |
|
| 133 |
y[0]['available_price'] = y[0]['available_price'] - y[0]['available_price'] * float(cashBack['cash_back'])/100
|
- |
|
| 134 |
elif cashBack['cash_back_type'] ==2:
|
- |
|
| 135 |
y[0]['available_price'] = y[0]['available_price'] - float(cashBack['cash_back'])
|
- |
|
| 136 |
else:
|
- |
|
| 137 |
pass
|
- |
|
| 138 |
sheet.write(it, 13, y[0]['available_price'])
|
- |
|
| 139 |
sheet.write(it, 14, x.mrp)
|
120 |
sheet.write(it, 13, x.mrp)
|
| 140 |
sheet.write(it, 15, x.dp)
|
121 |
sheet.write(it, 14, x.dp)
|
| 141 |
sheet.write(it, 16, x.schemeAmount)
|
122 |
sheet.write(it, 15, x.schemeAmount)
|
| 142 |
sheet.write(it, 17, x.discountType)
|
123 |
sheet.write(it, 16, x.discountType)
|
| 143 |
sheet.write(it, 18, x.minDiscount)
|
124 |
sheet.write(it, 17, x.minDiscount)
|
| 144 |
sheet.write(it, 19, x.maxDiscount)
|
125 |
sheet.write(it, 18, x.maxDiscount)
|
| 145 |
sheet.write(it, 20, x.maxNlc)
|
126 |
sheet.write(it, 19, x.maxNlc)
|
| 146 |
sheet.write(it, 21, x.minNlc)
|
127 |
sheet.write(it, 20, x.minNlc)
|
| 147 |
sheet.write(it, 22, x.maxprice)
|
128 |
sheet.write(it, 21, x.maxprice)
|
| 148 |
sheet.write(it, 23, x.rank)
|
129 |
sheet.write(it, 22, x.rank)
|
| 149 |
sheet.write(it, 24, x.nlcPoints)
|
130 |
sheet.write(it, 23, x.nlcPoints)
|
| 150 |
sheet.write(it, 25, x.bestSellerPoints)
|
131 |
sheet.write(it, 24, x.bestSellerPoints)
|
| 151 |
sheet.write(it, 26, x.catalogBestSellerPoints)
|
132 |
sheet.write(it, 25, x.catalogBestSellerPoints)
|
| 152 |
sheet.write(it, 27, x.totalPoints)
|
133 |
sheet.write(it, 26, x.totalPoints)
|
| 153 |
sheet.write(it, 28, x.showDeal)
|
134 |
sheet.write(it, 27, x.showDeal)
|
| 154 |
sheet.write(it, 29, x.showDealOld)
|
- |
|
| 155 |
it+=1
|
135 |
it+=1
|
| 156 |
filename = "/tmp/deal-data"+str(datetime.now())+".xls"
|
136 |
filename = "/tmp/deal-data"+str(datetime.now())+".xls"
|
| 157 |
wbk.save(filename)
|
137 |
wbk.save(filename)
|
| 158 |
smtpServer = smtplib.SMTP('localhost')
|
138 |
smtpServer = smtplib.SMTP('localhost')
|
| 159 |
#smtpServer.set_debuglevel(1)
|
139 |
#smtpServer.set_debuglevel(1)
|