| 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 = []
|
| 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']
|
| 16130 |
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 |
|
| 16131 |
kshitij.so |
20 |
SOURCE_MAP = {1:'AMAZON',2:'FLIPKART',3:'SNAPDEAL',4:'SAHOLIC',5:"SHOPCLUES.COM"}
|
|
|
21 |
|
| 16130 |
kshitij.so |
22 |
class __Items():
|
|
|
23 |
|
| 16131 |
kshitij.so |
24 |
def __init__(self, skuId, skuBundleId ,productName, source_id, rank, url):
|
| 16130 |
kshitij.so |
25 |
self.skuId = skuId
|
|
|
26 |
self.skuBundleId = skuBundleId
|
|
|
27 |
self.productName = productName
|
|
|
28 |
self.source_id = source_id
|
|
|
29 |
self.rank = rank
|
| 16131 |
kshitij.so |
30 |
self.url = url
|
| 16130 |
kshitij.so |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
|
|
35 |
global con
|
|
|
36 |
if con is None:
|
|
|
37 |
print "Establishing connection %s host and port %d" %(host,port)
|
|
|
38 |
try:
|
|
|
39 |
con = pymongo.MongoClient(host, port)
|
|
|
40 |
except Exception, e:
|
|
|
41 |
print e
|
|
|
42 |
return None
|
|
|
43 |
return con
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
def checkItems():
|
|
|
47 |
global ITEMS
|
|
|
48 |
negativeItems = get_mongo_connection().Catalog.NegativeDeals.find()
|
|
|
49 |
for negativeItem in negativeItems:
|
|
|
50 |
masterItem = get_mongo_connection().Catalog.MasterData.find_one({'_id':negativeItem['sku']})
|
| 16131 |
kshitij.so |
51 |
item = __Items(masterItem.get('_id'), masterItem.get('skuBundleId') ,masterItem.get('product_name'),masterItem.get('source_id'),masterItem.get('rank'), \
|
|
|
52 |
masterItem.get('marketPlaceUrl'))
|
| 16130 |
kshitij.so |
53 |
ITEMS.append(item)
|
|
|
54 |
|
|
|
55 |
def sendMail():
|
|
|
56 |
message="""<html>
|
|
|
57 |
<body>
|
|
|
58 |
<h3>Negative Items</h3>
|
|
|
59 |
<table border="1" style="width:100%;">
|
|
|
60 |
<thead>
|
|
|
61 |
<tr><th>Item Id</th>
|
|
|
62 |
<th>Catalog Item Id</th>
|
|
|
63 |
<th>Product Name</th>
|
|
|
64 |
<th>Rank</th>
|
| 16131 |
kshitij.so |
65 |
<th>Source</th>
|
|
|
66 |
<th>Url</th>
|
| 16130 |
kshitij.so |
67 |
</tr></thead>
|
|
|
68 |
<tbody>"""
|
|
|
69 |
for item in ITEMS:
|
|
|
70 |
message+="""<tr>
|
|
|
71 |
<td style="text-align:center">"""+str(item.skuId)+"""</td>
|
|
|
72 |
<td style="text-align:center">"""+str(item.skuBundleId)+"""</td>
|
|
|
73 |
<td style="text-align:center">"""+(item.productName)+"""</td>
|
|
|
74 |
<td style="text-align:center">"""+str(item.rank)+"""</td>
|
| 16131 |
kshitij.so |
75 |
<td style="text-align:center">"""+str(getSourceForId(item.source_id))+"""</td>
|
|
|
76 |
<td style="text-align:center">"""+str(item.url)+"""</td>
|
| 16130 |
kshitij.so |
77 |
</tr>"""
|
|
|
78 |
message+="""</tbody></table></body></html>"""
|
|
|
79 |
print message
|
|
|
80 |
msg = MIMEMultipart()
|
|
|
81 |
msg['Subject'] = "Negative Items" + ' - ' + str(datetime.now())
|
|
|
82 |
msg['From'] = ""
|
|
|
83 |
msg['To'] = ",".join(RECIPIENTS)
|
|
|
84 |
msg.preamble = "Negative Items" + ' - ' + str(datetime.now())
|
|
|
85 |
html_msg = MIMEText(message, 'html')
|
|
|
86 |
msg.attach(html_msg)
|
|
|
87 |
|
|
|
88 |
smtpServer = smtplib.SMTP('localhost')
|
|
|
89 |
smtpServer.set_debuglevel(1)
|
|
|
90 |
sender = 'dtr@shop2020.in'
|
|
|
91 |
try:
|
|
|
92 |
smtpServer.sendmail(sender, RECIPIENTS, msg.as_string())
|
|
|
93 |
print "Successfully sent email"
|
|
|
94 |
except:
|
|
|
95 |
print "Error: unable to send email."
|
|
|
96 |
|
| 16131 |
kshitij.so |
97 |
def getSourceForId(source_id):
|
|
|
98 |
if SOURCE_MAP.get(source_id) is not None:
|
|
|
99 |
return SOURCE_MAP.get(source_id)
|
|
|
100 |
else:
|
|
|
101 |
return "Not valid source"
|
|
|
102 |
|
| 16130 |
kshitij.so |
103 |
if __name__=='__main__':
|
|
|
104 |
checkItems()
|
|
|
105 |
sendMail()
|