| 14421 |
kshitij.so |
1 |
import pymongo
|
|
|
2 |
import optparse
|
|
|
3 |
import smtplib
|
|
|
4 |
from email.mime.text import MIMEText
|
|
|
5 |
from email.mime.multipart import MIMEMultipart
|
|
|
6 |
from datetime import datetime
|
|
|
7 |
|
|
|
8 |
ITEMS = []
|
| 20172 |
aman.kumar |
9 |
RECIPIENTS = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','ritesh.chauhan@saholic.com','khushal.bhatia@saholic.com']
|
| 14421 |
kshitij.so |
10 |
|
|
|
11 |
con = None
|
|
|
12 |
parser = optparse.OptionParser()
|
|
|
13 |
parser.add_option("-m", "--m", dest="mongoHost",
|
|
|
14 |
default="localhost",
|
|
|
15 |
type="string", help="The HOST where the mongo server is running",
|
|
|
16 |
metavar="mongo_host")
|
|
|
17 |
|
|
|
18 |
(options, args) = parser.parse_args()
|
|
|
19 |
|
|
|
20 |
class __Items():
|
|
|
21 |
|
|
|
22 |
def __init__(self, skuId, skuBundleId ,productName, source_id, rank):
|
|
|
23 |
self.skuId = skuId
|
|
|
24 |
self.skuBundleId = skuBundleId
|
|
|
25 |
self.productName = productName
|
|
|
26 |
self.source_id = source_id
|
|
|
27 |
self.rank = rank
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
|
| 14423 |
kshitij.so |
31 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
| 14421 |
kshitij.so |
32 |
global con
|
|
|
33 |
if con is None:
|
|
|
34 |
print "Establishing connection %s host and port %d" %(host,port)
|
|
|
35 |
try:
|
|
|
36 |
con = pymongo.MongoClient(host, port)
|
|
|
37 |
except Exception, e:
|
|
|
38 |
print e
|
|
|
39 |
return None
|
|
|
40 |
return con
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
def checkItems():
|
|
|
44 |
global ITEMS
|
|
|
45 |
uniqueBundles = get_mongo_connection().Catalog.Deals.find({'rank':{"$gt":0}}).distinct('skuBundleId')
|
|
|
46 |
dealData = get_mongo_connection().Catalog.Deals.find({"$and":[{"skuBundleId":{"$in":uniqueBundles}},{"$or":[{"maxNlc":None},{"minNlc":None}]}]})
|
|
|
47 |
for deal in dealData:
|
|
|
48 |
masterItem = list(get_mongo_connection().Catalog.MasterData.find({'_id':deal['_id']}))
|
|
|
49 |
item = __Items(deal['_id'], deal['skuBundleId'] ,masterItem[0]['product_name'],deal['source_id'],deal['rank'])
|
|
|
50 |
ITEMS.append(item)
|
|
|
51 |
|
|
|
52 |
def sendMail():
|
|
|
53 |
message="""<html>
|
|
|
54 |
<body>
|
|
|
55 |
<h3>No Max/Min NLC for BestSellers</h3>
|
|
|
56 |
<table border="1" style="width:100%;">
|
|
|
57 |
<thead>
|
|
|
58 |
<tr><th>Item Id</th>
|
|
|
59 |
<th>Catalog Item Id</th>
|
|
|
60 |
<th>Product Name</th>
|
|
|
61 |
<th>Rank</th>
|
|
|
62 |
</tr></thead>
|
|
|
63 |
<tbody>"""
|
|
|
64 |
for item in ITEMS:
|
|
|
65 |
message+="""<tr>
|
|
|
66 |
<td style="text-align:center">"""+str(item.skuId)+"""</td>
|
|
|
67 |
<td style="text-align:center">"""+str(item.skuBundleId)+"""</td>
|
|
|
68 |
<td style="text-align:center">"""+(item.productName)+"""</td>
|
|
|
69 |
<td style="text-align:center">"""+str(item.rank)+"""</td>
|
|
|
70 |
</tr>"""
|
|
|
71 |
message+="""</tbody></table></body></html>"""
|
|
|
72 |
print message
|
|
|
73 |
msg = MIMEMultipart()
|
|
|
74 |
msg['Subject'] = "No NLC Items" + ' - ' + str(datetime.now())
|
|
|
75 |
msg['From'] = ""
|
|
|
76 |
msg['To'] = ",".join(RECIPIENTS)
|
|
|
77 |
msg.preamble = "No NLC Items" + ' - ' + str(datetime.now())
|
|
|
78 |
html_msg = MIMEText(message, 'html')
|
|
|
79 |
msg.attach(html_msg)
|
|
|
80 |
|
|
|
81 |
smtpServer = smtplib.SMTP('localhost')
|
|
|
82 |
smtpServer.set_debuglevel(1)
|
|
|
83 |
sender = 'dtr@shop2020.in'
|
|
|
84 |
try:
|
|
|
85 |
smtpServer.sendmail(sender, RECIPIENTS, msg.as_string())
|
|
|
86 |
print "Successfully sent email"
|
|
|
87 |
except:
|
|
|
88 |
print "Error: unable to send email."
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
if __name__=='__main__':
|
|
|
92 |
checkItems()
|
|
|
93 |
sendMail()
|