| 13884 |
kshitij.so |
1 |
import pymongo
|
|
|
2 |
import xlwt
|
|
|
3 |
from datetime import datetime
|
|
|
4 |
from email.mime.multipart import MIMEMultipart
|
|
|
5 |
import email.encoders
|
|
|
6 |
import smtplib
|
| 16637 |
manish.sha |
7 |
import traceback
|
| 13884 |
kshitij.so |
8 |
|
|
|
9 |
con = None
|
|
|
10 |
|
| 14416 |
kshitij.so |
11 |
statusMap = {1:'Active',2:'EOL',3:'In Process',4:'Exclusive'}
|
|
|
12 |
|
| 13884 |
kshitij.so |
13 |
class __SkuInfo:
|
|
|
14 |
|
|
|
15 |
def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
|
| 16020 |
kshitij.so |
16 |
maxDiscount, discountType, dp, nlcPoints, bestSellerPoints, totalPoints,in_stock,maxprice,showDeal, catalogBestSellerPoints, prepaidDeal):
|
| 13884 |
kshitij.so |
17 |
self._id = _id
|
|
|
18 |
self.skuBundleId = skuBundleId
|
|
|
19 |
self.category_id = category_id
|
|
|
20 |
self.mrp = mrp
|
|
|
21 |
self.available_price = available_price
|
|
|
22 |
self.source_id = source_id
|
|
|
23 |
self.rank = rank
|
|
|
24 |
self.maxNlc = maxNlc
|
|
|
25 |
self.minNlc = minNlc
|
|
|
26 |
self.schemeAmount = schemeAmount
|
|
|
27 |
self.minDiscount = minDiscount
|
|
|
28 |
self.maxDiscount = maxDiscount
|
|
|
29 |
self.discountType = discountType
|
|
|
30 |
self.dp = dp
|
|
|
31 |
self.nlcPoints = nlcPoints
|
|
|
32 |
self.bestSellerPoints = bestSellerPoints
|
|
|
33 |
self.totalPoints = totalPoints
|
|
|
34 |
self.in_stock = in_stock
|
| 13906 |
kshitij.so |
35 |
self.maxprice = maxprice
|
| 14115 |
kshitij.so |
36 |
self.showDeal = showDeal
|
| 16020 |
kshitij.so |
37 |
self.catalogBestSellerPoints = catalogBestSellerPoints
|
|
|
38 |
self.prepaidDeal = prepaidDeal
|
| 13884 |
kshitij.so |
39 |
|
|
|
40 |
def get_mongo_connection(host='localhost', port=27017):
|
|
|
41 |
global con
|
|
|
42 |
if con is None:
|
|
|
43 |
print "Establishing connection %s host and port %d" %(host,port)
|
|
|
44 |
try:
|
|
|
45 |
con = pymongo.MongoClient(host, port)
|
|
|
46 |
except Exception, e:
|
|
|
47 |
print e
|
|
|
48 |
return None
|
|
|
49 |
return con
|
|
|
50 |
|
| 13904 |
kshitij.so |
51 |
def writeSheet():
|
|
|
52 |
p = []
|
| 13884 |
kshitij.so |
53 |
data = get_mongo_connection().Catalog.Deals.find().sort([('totalPoints',pymongo.DESCENDING)])
|
|
|
54 |
print data.count()
|
|
|
55 |
for x in data:
|
| 16027 |
kshitij.so |
56 |
if x['source_id'] == 5 and x['rank'] ==0:
|
|
|
57 |
continue
|
| 16869 |
kshitij.so |
58 |
s_info = __SkuInfo(x['_id'], x['skuBundleId'], x['category_id'],x['mrp'],x['available_price'],x['source_id'],x['rank'],x['maxNlc'], \
|
|
|
59 |
x['minNlc'], x['schemeAmount'],x['minDiscount'],x['maxDiscount'],x['discountType'],x['dp'],x['nlcPoints'],x['bestSellerPoints'], \
|
|
|
60 |
x['totalPoints'],x['in_stock'],x['maxprice'],x['showDeal'],x['catalogBestSellerPoints'],x['prepaidDeal'])
|
| 13884 |
kshitij.so |
61 |
p.append(s_info)
|
| 13904 |
kshitij.so |
62 |
|
| 13884 |
kshitij.so |
63 |
wbk = xlwt.Workbook()
|
|
|
64 |
sheet = wbk.add_sheet('Deals')
|
|
|
65 |
xstr = lambda s: s or ""
|
|
|
66 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap off, vert centre, horiz center')
|
|
|
67 |
|
|
|
68 |
excel_integer_format = '0'
|
|
|
69 |
integer_style = xlwt.XFStyle()
|
|
|
70 |
integer_style.num_format_str = excel_integer_format
|
|
|
71 |
|
|
|
72 |
sheet.write(0, 0, "Item ID", heading_xf)
|
|
|
73 |
sheet.write(0, 1, "Catalog Item Id", heading_xf)
|
|
|
74 |
sheet.write(0, 2, "Category", heading_xf)
|
|
|
75 |
sheet.write(0, 3, "Brand", heading_xf)
|
|
|
76 |
sheet.write(0, 4, "Product Name", heading_xf)
|
|
|
77 |
sheet.write(0, 5, "Item Status", heading_xf)
|
|
|
78 |
sheet.write(0, 6, "Stock Status", heading_xf)
|
|
|
79 |
sheet.write(0, 7, "MarketPlace", heading_xf)
|
|
|
80 |
sheet.write(0, 8, "MarketPlace Identifier", heading_xf)
|
|
|
81 |
sheet.write(0, 9, "MarketPlace Secondary Identifier", heading_xf)
|
|
|
82 |
sheet.write(0, 10, "Product Name (Marketplace)", heading_xf)
|
|
|
83 |
sheet.write(0, 11, "Url", heading_xf)
|
|
|
84 |
sheet.write(0, 12, "Price", heading_xf)
|
| 14812 |
kshitij.so |
85 |
sheet.write(0, 13, "Mrp", heading_xf)
|
|
|
86 |
sheet.write(0, 14, "DP", heading_xf)
|
|
|
87 |
sheet.write(0, 15, "Scheme Amount", heading_xf)
|
|
|
88 |
sheet.write(0, 16, "Discount Type", heading_xf)
|
|
|
89 |
sheet.write(0, 17, "Min Discount", heading_xf)
|
|
|
90 |
sheet.write(0, 18, "Max Discount", heading_xf)
|
|
|
91 |
sheet.write(0, 19, "Max Nlc", heading_xf)
|
|
|
92 |
sheet.write(0, 20, "Min Nlc", heading_xf)
|
|
|
93 |
sheet.write(0, 21, "Max Price", heading_xf)
|
|
|
94 |
sheet.write(0, 22, "Rank", heading_xf)
|
|
|
95 |
sheet.write(0, 23, "Nlc Points", heading_xf)
|
|
|
96 |
sheet.write(0, 24, "Best Seller Points", heading_xf)
|
|
|
97 |
sheet.write(0, 25, "Catalog Best Seller Points", heading_xf)
|
|
|
98 |
sheet.write(0, 26, "Total Points", heading_xf)
|
| 16020 |
kshitij.so |
99 |
sheet.write(0, 27, "COD Deal", heading_xf)
|
|
|
100 |
sheet.write(0, 28, "Prepaid Deal", heading_xf)
|
| 13884 |
kshitij.so |
101 |
|
|
|
102 |
it = 1
|
|
|
103 |
for x in p:
|
|
|
104 |
y = list(get_mongo_connection().Catalog.MasterData.find({'_id':x._id}))
|
|
|
105 |
sheet.write(it, 0, x._id)
|
|
|
106 |
sheet.write(it, 1, x.skuBundleId)
|
|
|
107 |
if x.category_id == 3:
|
|
|
108 |
category = 'Mobiles'
|
| 17546 |
kshitij.so |
109 |
elif x.category_id ==5:
|
|
|
110 |
category = 'Tablets'
|
| 13884 |
kshitij.so |
111 |
else:
|
| 17546 |
kshitij.so |
112 |
category = 'Accessories'
|
| 13884 |
kshitij.so |
113 |
sheet.write(it, 2, category)
|
|
|
114 |
sheet.write(it, 3, y[0]['brand'])
|
|
|
115 |
sheet.write(it, 4, y[0]['product_name'])
|
| 14416 |
kshitij.so |
116 |
sheet.write(it, 5, statusMap.get(y[0]['status']))
|
| 13884 |
kshitij.so |
117 |
if y[0]['in_stock'] ==1:
|
|
|
118 |
sheet.write(it, 6, 'In Stock')
|
|
|
119 |
else:
|
|
|
120 |
sheet.write(it, 6, 'Out Of Stock')
|
|
|
121 |
sheet.write(it, 7, y[0]['source'])
|
|
|
122 |
sheet.write(it, 8, y[0]['identifier'])
|
|
|
123 |
sheet.write(it, 9, y[0]['secondaryIdentifier'])
|
|
|
124 |
sheet.write(it, 10, y[0]['source_product_name'])
|
| 14860 |
kshitij.so |
125 |
sheet.write(it, 11, y[0]['marketPlaceUrl'])
|
| 13884 |
kshitij.so |
126 |
sheet.write(it, 12, y[0]['available_price'])
|
| 14812 |
kshitij.so |
127 |
sheet.write(it, 13, x.mrp)
|
|
|
128 |
sheet.write(it, 14, x.dp)
|
|
|
129 |
sheet.write(it, 15, x.schemeAmount)
|
|
|
130 |
sheet.write(it, 16, x.discountType)
|
|
|
131 |
sheet.write(it, 17, x.minDiscount)
|
|
|
132 |
sheet.write(it, 18, x.maxDiscount)
|
|
|
133 |
sheet.write(it, 19, x.maxNlc)
|
|
|
134 |
sheet.write(it, 20, x.minNlc)
|
|
|
135 |
sheet.write(it, 21, x.maxprice)
|
|
|
136 |
sheet.write(it, 22, x.rank)
|
|
|
137 |
sheet.write(it, 23, x.nlcPoints)
|
|
|
138 |
sheet.write(it, 24, x.bestSellerPoints)
|
|
|
139 |
sheet.write(it, 25, x.catalogBestSellerPoints)
|
|
|
140 |
sheet.write(it, 26, x.totalPoints)
|
|
|
141 |
sheet.write(it, 27, x.showDeal)
|
| 16020 |
kshitij.so |
142 |
sheet.write(it, 28, x.prepaidDeal)
|
| 13884 |
kshitij.so |
143 |
it+=1
|
|
|
144 |
filename = "/tmp/deal-data"+str(datetime.now())+".xls"
|
|
|
145 |
wbk.save(filename)
|
|
|
146 |
smtpServer = smtplib.SMTP('localhost')
|
| 13909 |
kshitij.so |
147 |
#smtpServer.set_debuglevel(1)
|
| 13884 |
kshitij.so |
148 |
sender = 'dtr@shop2020.in'
|
| 13896 |
kshitij.so |
149 |
#recipients = ['kshitij.sood@saholic.com']
|
| 13884 |
kshitij.so |
150 |
msg = MIMEMultipart()
|
|
|
151 |
msg['Subject'] = "DTR Deals data" + ' - ' + str(datetime.now())
|
|
|
152 |
msg['From'] = sender
|
| 20172 |
aman.kumar |
153 |
recipients = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','ritesh.chauhan@saholic.com','khushal.bhatia@saholic.com']
|
| 13884 |
kshitij.so |
154 |
msg['To'] = ",".join(recipients)
|
|
|
155 |
fileMsg = email.mime.base.MIMEBase('application','vnd.ms-excel')
|
|
|
156 |
fileMsg.set_payload(file(filename).read())
|
|
|
157 |
email.encoders.encode_base64(fileMsg)
|
| 13898 |
kshitij.so |
158 |
fileMsg.add_header('Content-Disposition','attachment;filename=Deal_Sheet_Dtr.xls')
|
| 13884 |
kshitij.so |
159 |
msg.attach(fileMsg)
|
|
|
160 |
try:
|
|
|
161 |
smtpServer.sendmail(sender, recipients, msg.as_string())
|
|
|
162 |
print "Successfully sent email"
|
|
|
163 |
except:
|
|
|
164 |
print "Error: unable to send email."
|
|
|
165 |
|
| 13893 |
kshitij.so |
166 |
def sendMail():
|
| 13884 |
kshitij.so |
167 |
writeSheet()
|
|
|
168 |
|
| 13893 |
kshitij.so |
169 |
def main():
|
|
|
170 |
sendMail()
|
|
|
171 |
|
| 13884 |
kshitij.so |
172 |
if __name__=='__main__':
|
|
|
173 |
main()
|