| 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
|
| 14777 |
kshitij.so |
13 |
from shop2020.utils.EmailAttachmentSender import mail_html
|
| 14723 |
kshitij.so |
14 |
|
|
|
15 |
order_list = []
|
| 20172 |
aman.kumar |
16 |
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', \
|
| 14777 |
kshitij.so |
17 |
'amit.sirohi@saholic.com','ritesh.chauhan@saholic.com','shailesh.kumar@saholic.com']
|
| 14723 |
kshitij.so |
18 |
|
|
|
19 |
class __Orders():
|
|
|
20 |
|
|
|
21 |
def __init__(self, id, transactionTime, status, amount):
|
|
|
22 |
self.id = id
|
|
|
23 |
self.transactionTime = transactionTime
|
|
|
24 |
self.status = status
|
|
|
25 |
self.amount = amount
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
def getUnknownTransactions():
|
| 14777 |
kshitij.so |
29 |
global order_list
|
| 14723 |
kshitij.so |
30 |
saholic_orders = RechargeOrder.query.filter_by(status=RechargeOrderStatus.PAYMENT_SUCCESSFUL).all()
|
|
|
31 |
for saholic_order in saholic_orders:
|
|
|
32 |
order = __Orders(saholic_order.id, saholic_order.creationTimestamp, 'Unknown', saholic_order.totalAmount)
|
|
|
33 |
order_list.append(order)
|
|
|
34 |
hotspot_orders = RechargeTransaction.query.filter_by(status = RechargeOrderStatus.RECHARGE_UNKNOWN).all()
|
|
|
35 |
for hotspot_order in hotspot_orders:
|
|
|
36 |
order = __Orders(hotspot_order.id, hotspot_order.transactionTime, 'Unknown', hotspot_order.amount)
|
|
|
37 |
order_list.append(order)
|
|
|
38 |
|
|
|
39 |
def sendAlert():
|
|
|
40 |
message="""<html>
|
|
|
41 |
<body>
|
|
|
42 |
<h3>Recharge Status Unknown</h3>
|
|
|
43 |
<table border="1" style="width:100%;">
|
|
|
44 |
<thead>
|
|
|
45 |
<tr><th>Order Id</th>
|
|
|
46 |
<th>Status</th>
|
|
|
47 |
<th>Amount</th>
|
|
|
48 |
<th>Transaction Time</th>
|
|
|
49 |
</tr></thead>
|
|
|
50 |
<tbody>"""
|
|
|
51 |
for order in order_list:
|
|
|
52 |
message+="""<tr>
|
|
|
53 |
<td style="text-align:center">"""+str(order.id)+"""</td>
|
|
|
54 |
<td style="text-align:center">"""+(order.status)+"""</td>
|
|
|
55 |
<td style="text-align:center">"""+str(order.amount)+"""</td>
|
|
|
56 |
<td style="text-align:center">"""+str(order.transactionTime)+"""</td>
|
|
|
57 |
</tr>"""
|
|
|
58 |
message+="""</tbody></table></body></html>"""
|
|
|
59 |
print message
|
| 14777 |
kshitij.so |
60 |
mail_html("cnc.center@shop2020.in", "5h0p2o2o", RECIPIENTS, "Recharge Status Unknown" + ' - ' + str(datetime.now()), message, [])
|
| 14723 |
kshitij.so |
61 |
|
|
|
62 |
def main():
|
|
|
63 |
parser = optparse.OptionParser()
|
|
|
64 |
parser.add_option("-H", "--host", dest="hostname",
|
|
|
65 |
default="localhost",
|
|
|
66 |
type="string", help="The HOST where the DB server is running",
|
|
|
67 |
metavar="HOST")
|
|
|
68 |
(options, args) = parser.parse_args()
|
|
|
69 |
try:
|
|
|
70 |
DataService.initialize(db_hostname=options.hostname, echoOn=True)
|
|
|
71 |
getUnknownTransactions()
|
|
|
72 |
sendAlert()
|
|
|
73 |
finally:
|
|
|
74 |
session.close()
|
|
|
75 |
if __name__=='__main__':
|
|
|
76 |
main()
|