| 14723 |
kshitij.so |
1 |
from elixir import *
|
|
|
2 |
from shop2020.model.v1.order.impl import DataService
|
|
|
3 |
from shop2020.model.v1.order.impl.DataService import RechargeTransaction
|
|
|
4 |
from shop2020.thriftpy.model.v1.order.ttypes import RechargeOrderStatus
|
|
|
5 |
from shop2020.model.v1.order.impl.model.RechargeOrder import RechargeOrder
|
|
|
6 |
from shop2020.model.v1.order.impl.model.MobileRechargeOrder import MobileRechargeOrder
|
|
|
7 |
from shop2020.model.v1.order.impl.model.DTHRechargeOrder import DTHRechargeOrder
|
|
|
8 |
import optparse
|
|
|
9 |
import smtplib
|
|
|
10 |
from email.mime.text import MIMEText
|
|
|
11 |
from email.mime.multipart import MIMEMultipart
|
|
|
12 |
from datetime import datetime
|
|
|
13 |
|
|
|
14 |
order_list = []
|
|
|
15 |
RECIPIENTS = ['mcom.support@spicedigital.in','mohit.mehral','rajneesh.arora@saholic.com','kshitij.sood@saholic.com','anikendra.das@saholic.com']
|
|
|
16 |
|
|
|
17 |
class __Orders():
|
|
|
18 |
|
|
|
19 |
def __init__(self, id, transactionTime, status, amount):
|
|
|
20 |
self.id = id
|
|
|
21 |
self.transactionTime = transactionTime
|
|
|
22 |
self.status = status
|
|
|
23 |
self.amount = amount
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
def getUnknownTransactions():
|
|
|
27 |
saholic_orders = RechargeOrder.query.filter_by(status=RechargeOrderStatus.PAYMENT_SUCCESSFUL).all()
|
|
|
28 |
for saholic_order in saholic_orders:
|
|
|
29 |
order = __Orders(saholic_order.id, saholic_order.creationTimestamp, 'Unknown', saholic_order.totalAmount)
|
|
|
30 |
order_list.append(order)
|
|
|
31 |
hotspot_orders = RechargeTransaction.query.filter_by(status = RechargeOrderStatus.RECHARGE_UNKNOWN).all()
|
|
|
32 |
for hotspot_order in hotspot_orders:
|
|
|
33 |
order = __Orders(hotspot_order.id, hotspot_order.transactionTime, 'Unknown', hotspot_order.amount)
|
|
|
34 |
order_list.append(order)
|
|
|
35 |
|
|
|
36 |
def sendAlert():
|
|
|
37 |
message="""<html>
|
|
|
38 |
<body>
|
|
|
39 |
<h3>Recharge Status Unknown</h3>
|
|
|
40 |
<table border="1" style="width:100%;">
|
|
|
41 |
<thead>
|
|
|
42 |
<tr><th>Order Id</th>
|
|
|
43 |
<th>Status</th>
|
|
|
44 |
<th>Amount</th>
|
|
|
45 |
<th>Transaction Time</th>
|
|
|
46 |
</tr></thead>
|
|
|
47 |
<tbody>"""
|
|
|
48 |
for order in order_list:
|
|
|
49 |
message+="""<tr>
|
|
|
50 |
<td style="text-align:center">"""+str(order.id)+"""</td>
|
|
|
51 |
<td style="text-align:center">"""+(order.status)+"""</td>
|
|
|
52 |
<td style="text-align:center">"""+str(order.amount)+"""</td>
|
|
|
53 |
<td style="text-align:center">"""+str(order.transactionTime)+"""</td>
|
|
|
54 |
</tr>"""
|
|
|
55 |
message+="""</tbody></table></body></html>"""
|
|
|
56 |
print message
|
|
|
57 |
msg = MIMEMultipart()
|
|
|
58 |
msg['Subject'] = "Recharge Status Unknown" + ' - ' + str(datetime.now())
|
|
|
59 |
msg['From'] = ""
|
|
|
60 |
msg['To'] = ",".join(RECIPIENTS)
|
|
|
61 |
msg.preamble = "Recharge Status Unknown" + ' - ' + str(datetime.now())
|
|
|
62 |
html_msg = MIMEText(message, 'html')
|
|
|
63 |
msg.attach(html_msg)
|
|
|
64 |
|
|
|
65 |
smtpServer = smtplib.SMTP('localhost')
|
|
|
66 |
smtpServer.set_debuglevel(1)
|
|
|
67 |
sender = 'cnc.center@shop2020.in'
|
|
|
68 |
try:
|
|
|
69 |
smtpServer.sendmail(sender, RECIPIENTS, msg.as_string())
|
|
|
70 |
print "Successfully sent email"
|
|
|
71 |
except:
|
|
|
72 |
print "Error: unable to send email."
|
|
|
73 |
|
|
|
74 |
def main():
|
|
|
75 |
parser = optparse.OptionParser()
|
|
|
76 |
parser.add_option("-H", "--host", dest="hostname",
|
|
|
77 |
default="localhost",
|
|
|
78 |
type="string", help="The HOST where the DB server is running",
|
|
|
79 |
metavar="HOST")
|
|
|
80 |
(options, args) = parser.parse_args()
|
|
|
81 |
try:
|
|
|
82 |
DataService.initialize(db_hostname=options.hostname, echoOn=True)
|
|
|
83 |
getUnknownTransactions()
|
|
|
84 |
sendAlert()
|
|
|
85 |
finally:
|
|
|
86 |
session.close()
|
|
|
87 |
if __name__=='__main__':
|
|
|
88 |
main()
|