Subversion Repositories SmartDukaan

Rev

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

from dtr.utils.utils import get_mongo_connection
import optparse
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from datetime import datetime

parser = optparse.OptionParser()
parser.add_option("-m", "--m", dest="mongoHost",
                      default="localhost",
                      type="string", help="The HOST where the mongo server is running",
                      metavar="HOST")

(options, args) = parser.parse_args()

SOURCE_MAP = {1:'AMAZON',2:'FLIPKART',3:'SNAPDEAL',4:'SAHOLIC',5:"SHOPCLUES.COM",6:"PAYTM.COM"}
RECIPIENTS = ['rajneesh.arora@saholic.com','kshitij.sood@saholic.com','chaitnaya.vats@saholic.com','ritesh.chauhan@saholic.com','khushal.bhatia@saholic.com']


def findAndMail():
    all_ignored_items = get_mongo_connection(host=options.mongoHost).Catalog.MasterData.find({'ignorePricing':1})
    message="""<html>
            <body>
            <h3>Ignore Pricing Items</h3>
            <table border="1" style="width:100%;">
            <thead>
            <tr><th>Item Id</th>
            <th>Catalog Item Id</th>
            <th>Product Name</th>
            <th>Source</th>
            </tr></thead>
            <tbody>"""
    for item in all_ignored_items:
        message+="""<tr>
        <td style="text-align:center">"""+str(item.get('_id'))+"""</td>
        <td style="text-align:center">"""+str(item.get('skuBundleId'))+"""</td>
        <td style="text-align:center">"""+item.get('source_product_name')+"""</td>
        <td style="text-align:center">"""+SOURCE_MAP.get(item.get('source_id'))+"""</td>
        </tr>"""
    message+="""</tbody></table></body></html>"""
    msg = MIMEMultipart()
    msg['Subject'] = "Ignore Pricing Items" + ' - ' + str(datetime.now())
    msg['From'] = ""
    msg['To'] = ",".join(RECIPIENTS)
    msg.preamble = "Ignore Pricing Items" + ' - ' + str(datetime.now())
    html_msg = MIMEText(message, 'html')
    msg.attach(html_msg)
    
    smtpServer = smtplib.SMTP('localhost')
    smtpServer.set_debuglevel(1)
    sender = 'dtr@shop2020.in'
    try:
        smtpServer.sendmail(sender, RECIPIENTS, msg.as_string())
        print "Successfully sent email"
    except:
        print "Error: unable to send email."

if __name__ == '__main__':
    findAndMail()