| 16130 |
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 = []
|
|
|
9 |
RECIPIENTS = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','manoj.kumar@saholic.com']
|
|
|
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 |
|
|
|
31 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
|
|
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 |
negativeItems = get_mongo_connection().Catalog.NegativeDeals.find()
|
|
|
46 |
for negativeItem in negativeItems:
|
|
|
47 |
masterItem = get_mongo_connection().Catalog.MasterData.find_one({'_id':negativeItem['sku']})
|
|
|
48 |
item = __Items(masterItem.get('_id'), masterItem.get('skuBundleId') ,masterItem.get('product_name'),masterItem.get('source_id'),masterItem.get('rank'))
|
|
|
49 |
ITEMS.append(item)
|
|
|
50 |
|
|
|
51 |
def sendMail():
|
|
|
52 |
message="""<html>
|
|
|
53 |
<body>
|
|
|
54 |
<h3>Negative Items</h3>
|
|
|
55 |
<table border="1" style="width:100%;">
|
|
|
56 |
<thead>
|
|
|
57 |
<tr><th>Item Id</th>
|
|
|
58 |
<th>Catalog Item Id</th>
|
|
|
59 |
<th>Product Name</th>
|
|
|
60 |
<th>Rank</th>
|
|
|
61 |
</tr></thead>
|
|
|
62 |
<tbody>"""
|
|
|
63 |
for item in ITEMS:
|
|
|
64 |
message+="""<tr>
|
|
|
65 |
<td style="text-align:center">"""+str(item.skuId)+"""</td>
|
|
|
66 |
<td style="text-align:center">"""+str(item.skuBundleId)+"""</td>
|
|
|
67 |
<td style="text-align:center">"""+(item.productName)+"""</td>
|
|
|
68 |
<td style="text-align:center">"""+str(item.rank)+"""</td>
|
|
|
69 |
</tr>"""
|
|
|
70 |
message+="""</tbody></table></body></html>"""
|
|
|
71 |
print message
|
|
|
72 |
msg = MIMEMultipart()
|
|
|
73 |
msg['Subject'] = "Negative Items" + ' - ' + str(datetime.now())
|
|
|
74 |
msg['From'] = ""
|
|
|
75 |
msg['To'] = ",".join(RECIPIENTS)
|
|
|
76 |
msg.preamble = "Negative Items" + ' - ' + str(datetime.now())
|
|
|
77 |
html_msg = MIMEText(message, 'html')
|
|
|
78 |
msg.attach(html_msg)
|
|
|
79 |
|
|
|
80 |
smtpServer = smtplib.SMTP('localhost')
|
|
|
81 |
smtpServer.set_debuglevel(1)
|
|
|
82 |
sender = 'dtr@shop2020.in'
|
|
|
83 |
try:
|
|
|
84 |
smtpServer.sendmail(sender, RECIPIENTS, msg.as_string())
|
|
|
85 |
print "Successfully sent email"
|
|
|
86 |
except:
|
|
|
87 |
print "Error: unable to send email."
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
if __name__=='__main__':
|
|
|
91 |
checkItems()
|
|
|
92 |
sendMail()
|