Subversion Repositories SmartDukaan

Rev

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

from elixir import *
from shop2020.model.v1.order.impl import DataService
from shop2020.model.v1.order.impl.DataService import RechargeTransaction
from shop2020.thriftpy.model.v1.order.ttypes import RechargeOrderStatus
from shop2020.model.v1.order.impl.model.RechargeOrder import RechargeOrder
from shop2020.model.v1.order.impl.model.MobileRechargeOrder import MobileRechargeOrder
from shop2020.model.v1.order.impl.model.DTHRechargeOrder import DTHRechargeOrder
import optparse
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from datetime import datetime
from shop2020.utils.EmailAttachmentSender import mail_html

order_list = []
RECIPIENTS = ['mcom.support@spicedigital.in','mohit.mehral@spicedigital.in','neeti.mittal@spicedigital.in','rajneesh.arora@saholic.com','kshitij.sood@saholic.com','khushal.bhatia@saholic.com', \
              'amit.sirohi@saholic.com','ritesh.chauhan@saholic.com','shailesh.kumar@saholic.com']

class __Orders():
    
    def __init__(self, id, transactionTime, status, amount):
        self.id = id
        self.transactionTime = transactionTime
        self.status = status
        self.amount = amount


def getUnknownTransactions():
    global order_list
    saholic_orders = RechargeOrder.query.filter_by(status=RechargeOrderStatus.PAYMENT_SUCCESSFUL).all()
    for saholic_order in saholic_orders:
        order =  __Orders(saholic_order.id, saholic_order.creationTimestamp, 'Unknown', saholic_order.totalAmount)
        order_list.append(order)
    hotspot_orders = RechargeTransaction.query.filter_by(status = RechargeOrderStatus.RECHARGE_UNKNOWN).all()
    for hotspot_order in hotspot_orders:
        order =  __Orders(hotspot_order.id, hotspot_order.transactionTime, 'Unknown', hotspot_order.amount)
        order_list.append(order)

def sendAlert():
    message="""<html>
            <body>
            <h3>Recharge Status Unknown</h3>
            <table border="1" style="width:100%;">
            <thead>
            <tr><th>Order Id</th>
            <th>Status</th>
            <th>Amount</th>
            <th>Transaction Time</th>
            </tr></thead>
            <tbody>"""
    for order in order_list:
        message+="""<tr>
        <td style="text-align:center">"""+str(order.id)+"""</td>
        <td style="text-align:center">"""+(order.status)+"""</td>
        <td style="text-align:center">"""+str(order.amount)+"""</td>
        <td style="text-align:center">"""+str(order.transactionTime)+"""</td>
        </tr>"""
    message+="""</tbody></table></body></html>"""
    print message
    mail_html("cnc.center@shop2020.in", "5h0p2o2o", RECIPIENTS, "Recharge Status Unknown" + ' - ' + str(datetime.now()), message, [])

def main():
    parser = optparse.OptionParser()
    parser.add_option("-H", "--host", dest="hostname",
                      default="localhost",
                      type="string", help="The HOST where the DB server is running",
                      metavar="HOST")
    (options, args) = parser.parse_args()
    try:
        DataService.initialize(db_hostname=options.hostname, echoOn=True)
        getUnknownTransactions()
        sendAlert()
    finally:
        session.close()
if __name__=='__main__':
    main()