Subversion Repositories SmartDukaan

Rev

Rev 16992 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
16990 kshitij.so 1
from dtr.utils.utils import get_mongo_connection
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
parser = optparse.OptionParser()
9
parser.add_option("-m", "--m", dest="mongoHost",
10
                      default="localhost",
11
                      type="string", help="The HOST where the mongo server is running",
12
                      metavar="HOST")
13
 
14
(options, args) = parser.parse_args()
15
 
16
SOURCE_MAP = {1:'AMAZON',2:'FLIPKART',3:'SNAPDEAL',4:'SAHOLIC',5:"SHOPCLUES.COM",6:"PAYTM.COM"}
20172 aman.kumar 17
RECIPIENTS = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','ritesh.chauhan@saholic.com','khushal.bhatia@saholic.com']
16990 kshitij.so 18
 
19
 
20
def findAndMail():
21
    all_ignored_items = get_mongo_connection(host=options.mongoHost).Catalog.MasterData.find({'ignorePricing':1})
22
    message="""<html>
23
            <body>
24
            <h3>Ignore Pricing Items</h3>
25
            <table border="1" style="width:100%;">
26
            <thead>
27
            <tr><th>Item Id</th>
28
            <th>Catalog Item Id</th>
29
            <th>Product Name</th>
30
            <th>Source</th>
31
            </tr></thead>
32
            <tbody>"""
33
    for item in all_ignored_items:
34
        message+="""<tr>
16992 kshitij.so 35
        <td style="text-align:center">"""+str(item.get('_id'))+"""</td>
16990 kshitij.so 36
        <td style="text-align:center">"""+str(item.get('skuBundleId'))+"""</td>
37
        <td style="text-align:center">"""+item.get('source_product_name')+"""</td>
38
        <td style="text-align:center">"""+SOURCE_MAP.get(item.get('source_id'))+"""</td>
39
        </tr>"""
40
    message+="""</tbody></table></body></html>"""
41
    msg = MIMEMultipart()
42
    msg['Subject'] = "Ignore Pricing Items" + ' - ' + str(datetime.now())
43
    msg['From'] = ""
44
    msg['To'] = ",".join(RECIPIENTS)
45
    msg.preamble = "Ignore Pricing Items" + ' - ' + str(datetime.now())
46
    html_msg = MIMEText(message, 'html')
47
    msg.attach(html_msg)
48
 
49
    smtpServer = smtplib.SMTP('localhost')
50
    smtpServer.set_debuglevel(1)
51
    sender = 'dtr@shop2020.in'
52
    try:
53
        smtpServer.sendmail(sender, RECIPIENTS, msg.as_string())
54
        print "Successfully sent email"
55
    except:
56
        print "Error: unable to send email."
57
 
58
if __name__ == '__main__':
59
    findAndMail()
60