| Line 1... |
Line 1... |
| 1 |
import pymongo
|
1 |
import pymongo
|
| 2 |
import xlwt
|
2 |
import xlwt
|
| 3 |
from datetime import datetime
|
3 |
from datetime import datetime
|
| 4 |
from shop2020.utils import EmailAttachmentSender
|
- |
|
| 5 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part
|
- |
|
| 6 |
from email.mime.text import MIMEText
|
- |
|
| 7 |
import email
|
- |
|
| 8 |
from email.mime.multipart import MIMEMultipart
|
4 |
from email.mime.multipart import MIMEMultipart
|
| 9 |
import email.encoders
|
5 |
import email.encoders
|
| 10 |
import smtplib
|
6 |
import smtplib
|
| 11 |
|
7 |
|
| 12 |
con = None
|
8 |
con = None
|
| 13 |
|
9 |
|
| 14 |
class __SkuInfo:
|
10 |
class __SkuInfo:
|
| 15 |
|
11 |
|
| 16 |
def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
|
12 |
def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
|
| 17 |
maxDiscount, discountType, dp, nlcPoints, bestSellerPoints, totalPoints,in_stock,maxprice,showDeal):
|
13 |
maxDiscount, discountType, dp, nlcPoints, bestSellerPoints, totalPoints,in_stock,maxprice,showDeal, catalogBestSellerPoints):
|
| 18 |
self._id = _id
|
14 |
self._id = _id
|
| 19 |
self.skuBundleId = skuBundleId
|
15 |
self.skuBundleId = skuBundleId
|
| 20 |
self.category_id = category_id
|
16 |
self.category_id = category_id
|
| 21 |
self.mrp = mrp
|
17 |
self.mrp = mrp
|
| 22 |
self.available_price = available_price
|
18 |
self.available_price = available_price
|
| Line 32... |
Line 28... |
| 32 |
self.nlcPoints = nlcPoints
|
28 |
self.nlcPoints = nlcPoints
|
| 33 |
self.bestSellerPoints = bestSellerPoints
|
29 |
self.bestSellerPoints = bestSellerPoints
|
| 34 |
self.totalPoints = totalPoints
|
30 |
self.totalPoints = totalPoints
|
| 35 |
self.in_stock = in_stock
|
31 |
self.in_stock = in_stock
|
| 36 |
self.maxprice = maxprice
|
32 |
self.maxprice = maxprice
|
| 37 |
self.showDeal = showDeal
|
33 |
self.showDeal = showDeal
|
| - |
|
34 |
self.catalogBestSellerPoints = catalogBestSellerPoints
|
| 38 |
|
35 |
|
| 39 |
def get_mongo_connection(host='localhost', port=27017):
|
36 |
def get_mongo_connection(host='localhost', port=27017):
|
| 40 |
global con
|
37 |
global con
|
| 41 |
if con is None:
|
38 |
if con is None:
|
| 42 |
print "Establishing connection %s host and port %d" %(host,port)
|
39 |
print "Establishing connection %s host and port %d" %(host,port)
|
| Line 52... |
Line 49... |
| 52 |
data = get_mongo_connection().Catalog.Deals.find().sort([('totalPoints',pymongo.DESCENDING)])
|
49 |
data = get_mongo_connection().Catalog.Deals.find().sort([('totalPoints',pymongo.DESCENDING)])
|
| 53 |
print data.count()
|
50 |
print data.count()
|
| 54 |
for x in data:
|
51 |
for x in data:
|
| 55 |
s_info = __SkuInfo(x['_id'], x['skuBundleId'], x['category_id'],x['mrp'],x['available_price'],x['source_id'],x['rank'],x['maxNlc'], \
|
52 |
s_info = __SkuInfo(x['_id'], x['skuBundleId'], x['category_id'],x['mrp'],x['available_price'],x['source_id'],x['rank'],x['maxNlc'], \
|
| 56 |
x['minNlc'], x['schemeAmount'],x['minDiscount'],x['maxDiscount'],x['discountType'],x['dp'],x['nlcPoints'],x['bestSellerPoints'], \
|
53 |
x['minNlc'], x['schemeAmount'],x['minDiscount'],x['maxDiscount'],x['discountType'],x['dp'],x['nlcPoints'],x['bestSellerPoints'], \
|
| 57 |
x['totalPoints'],x['in_stock'],x['maxprice'],x['showDeal'])
|
54 |
x['totalPoints'],x['in_stock'],x['maxprice'],x['showDeal'],x['catalogBestSellerPoints'])
|
| 58 |
p.append(s_info)
|
55 |
p.append(s_info)
|
| 59 |
|
56 |
|
| 60 |
wbk = xlwt.Workbook()
|
57 |
wbk = xlwt.Workbook()
|
| 61 |
sheet = wbk.add_sheet('Deals')
|
58 |
sheet = wbk.add_sheet('Deals')
|
| 62 |
xstr = lambda s: s or ""
|
59 |
xstr = lambda s: s or ""
|
| Line 89... |
Line 86... |
| 89 |
sheet.write(0, 20, "Min Nlc", heading_xf)
|
86 |
sheet.write(0, 20, "Min Nlc", heading_xf)
|
| 90 |
sheet.write(0, 21, "Max Price", heading_xf)
|
87 |
sheet.write(0, 21, "Max Price", heading_xf)
|
| 91 |
sheet.write(0, 22, "Rank", heading_xf)
|
88 |
sheet.write(0, 22, "Rank", heading_xf)
|
| 92 |
sheet.write(0, 23, "Nlc Points", heading_xf)
|
89 |
sheet.write(0, 23, "Nlc Points", heading_xf)
|
| 93 |
sheet.write(0, 24, "Best Seller Points", heading_xf)
|
90 |
sheet.write(0, 24, "Best Seller Points", heading_xf)
|
| - |
|
91 |
sheet.write(0, 25, "Catalog Best Seller Points", heading_xf)
|
| 94 |
sheet.write(0, 25, "Total Points", heading_xf)
|
92 |
sheet.write(0, 26, "Total Points", heading_xf)
|
| 95 |
sheet.write(0, 26, "Show Deals", heading_xf)
|
93 |
sheet.write(0, 27, "Show Deals", heading_xf)
|
| 96 |
|
94 |
|
| 97 |
it = 1
|
95 |
it = 1
|
| 98 |
for x in p:
|
96 |
for x in p:
|
| 99 |
y = list(get_mongo_connection().Catalog.MasterData.find({'_id':x._id}))
|
97 |
y = list(get_mongo_connection().Catalog.MasterData.find({'_id':x._id}))
|
| 100 |
sheet.write(it, 0, x._id)
|
98 |
sheet.write(it, 0, x._id)
|
| Line 130... |
Line 128... |
| 130 |
sheet.write(it, 20, x.minNlc)
|
128 |
sheet.write(it, 20, x.minNlc)
|
| 131 |
sheet.write(it, 21, x.maxprice)
|
129 |
sheet.write(it, 21, x.maxprice)
|
| 132 |
sheet.write(it, 22, x.rank)
|
130 |
sheet.write(it, 22, x.rank)
|
| 133 |
sheet.write(it, 23, x.nlcPoints)
|
131 |
sheet.write(it, 23, x.nlcPoints)
|
| 134 |
sheet.write(it, 24, x.bestSellerPoints)
|
132 |
sheet.write(it, 24, x.bestSellerPoints)
|
| - |
|
133 |
sheet.write(it, 24, x.catalogBestSellerPoints)
|
| 135 |
sheet.write(it, 25, x.totalPoints)
|
134 |
sheet.write(it, 26, x.totalPoints)
|
| 136 |
sheet.write(it, 26, x.showDeal)
|
135 |
sheet.write(it, 27, x.showDeal)
|
| 137 |
it+=1
|
136 |
it+=1
|
| 138 |
filename = "/tmp/deal-data"+str(datetime.now())+".xls"
|
137 |
filename = "/tmp/deal-data"+str(datetime.now())+".xls"
|
| 139 |
wbk.save(filename)
|
138 |
wbk.save(filename)
|
| 140 |
smtpServer = smtplib.SMTP('localhost')
|
139 |
smtpServer = smtplib.SMTP('localhost')
|
| 141 |
#smtpServer.set_debuglevel(1)
|
140 |
#smtpServer.set_debuglevel(1)
|