| Line 23... |
Line 23... |
| 23 |
from shop2020.model.v1.order.impl import DataService
|
23 |
from shop2020.model.v1.order.impl import DataService
|
| 24 |
from shop2020.model.v1.order.impl.DataService import RechargeVoucherTracker
|
24 |
from shop2020.model.v1.order.impl.DataService import RechargeVoucherTracker
|
| 25 |
from shop2020.thriftpy.model.v1.user.ttypes import Voucher, VoucherType
|
25 |
from shop2020.thriftpy.model.v1.user.ttypes import Voucher, VoucherType
|
| 26 |
from elixir import session
|
26 |
from elixir import session
|
| 27 |
|
27 |
|
| 28 |
voucherGenerationUrl = "http://www.spicedeck.com/mcommerce/couponregister.sdesk";
|
28 |
voucherGenerationUrl = "http://www.spicedeck.com/couponregister.sdesk"
|
| 29 |
voucherActivationUrl = "http://www.spicedeck.com/mcommerce/couponassign.sdesk";
|
29 |
voucherActivationUrl = "http://www.spicedeck.com/couponassign.sdesk"
|
| - |
|
30 |
voucherDeactivationUrl = "http://www.spicedeck.com/coupondeact.sdesk"
|
| - |
|
31 |
voucherStatusUrl = "http://www.spicedeck.com/couponstatus.sdesk"
|
| - |
|
32 |
username = "saholic"
|
| - |
|
33 |
password = "abc1234"
|
| 30 |
|
34 |
|
| 31 |
def issue_voucher_to_orders(days, db_hostname):
|
35 |
def issue_voucher_to_orders(days, db_hostname):
|
| 32 |
DataService.initialize(db_hostname=db_hostname, echoOn=True)
|
36 |
DataService.initialize(db_hostname=db_hostname, echoOn=True)
|
| 33 |
current_time = datetime.datetime.now()
|
37 |
current_time = datetime.datetime.now()
|
| 34 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
38 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
| 35 |
to_datetime = to_datetime - datetime.timedelta(days-1)
|
39 |
to_datetime = to_datetime - datetime.timedelta(days-1)
|
| 36 |
vouchers = RechargeVoucherTracker.query.filter_by(voucherIssued=False).all()
|
40 |
vouchers = RechargeVoucherTracker.query.filter_by(voucherIssued=False).all()
|
| 37 |
for voucher in vouchers:
|
41 |
for voucher in vouchers:
|
| 38 |
order = voucher.order
|
42 |
order = voucher.order
|
| 39 |
if order.status == OrderStatus.DELIVERY_SUCCESS and order.delivery_timestamp <= to_datetime:
|
43 |
if order.status == OrderStatus.DELIVERY_SUCCESS and order.delivery_timestamp <= to_datetime:
|
| 40 |
storeVoucher("sachingyal", "abc1234", voucher.amount)
|
44 |
storeVoucher(voucher.amount)
|
| 41 |
coupon = issueVoucher("sachingyal", "abc1234", order.customer_id, order.customer_email, voucher.amount)
|
45 |
coupon = issueVoucher(order.customer_id, order.customer_email, voucher.amount)
|
| 42 |
voucher.issuedOn = current_time
|
46 |
voucher.issuedOn = current_time
|
| 43 |
voucher.voucherIssued = True
|
47 |
voucher.voucherIssued = True
|
| 44 |
voucher.voucherCode = coupon
|
48 |
voucher.voucherCode = coupon
|
| 45 |
sendEmail(order.customer_email, voucher.amount, order.id, coupon)
|
49 |
#sendEmail(order.customer_email, voucher.amount, order.id, coupon)
|
| 46 |
session.commit()
|
50 |
session.commit()
|
| 47 |
|
51 |
|
| 48 |
|
52 |
|
| 49 |
def storeVoucher(username, password, amount):
|
53 |
def storeVoucher(amount):
|
| 50 |
coupon = generateVoucher(username, password, amount)
|
54 |
coupon = generateVoucher(amount)
|
| 51 |
voucher = Voucher()
|
55 |
voucher = Voucher()
|
| 52 |
voucher.voucherCode = coupon
|
56 |
voucher.voucherCode = coupon
|
| 53 |
voucher.voucherType = VoucherType.SPICEDECK_MOBILE
|
57 |
voucher.voucherType = VoucherType.SPICEDECK_MOBILE
|
| 54 |
voucher.amount = amount
|
58 |
voucher.amount = amount
|
| 55 |
pc = PromotionClient().get_client()
|
59 |
pc = PromotionClient().get_client()
|
| 56 |
pc.addVoucher(voucher)
|
60 |
pc.addVoucher(voucher)
|
| 57 |
|
61 |
|
| 58 |
def generateVoucher(username, password, amount):
|
62 |
def generateVoucher(amount):
|
| 59 |
params = "userid=" + username + "&password=" + password + "&amount=" + str(amount)
|
63 |
params = "userid=" + username + "&password=" + password + "&amount=" + str(amount)
|
| 60 |
returnValue = urllib2.urlopen(voucherGenerationUrl + "?" + params).read()
|
64 |
returnValue = urllib2.urlopen(voucherGenerationUrl + "?" + params).read()
|
| 61 |
if "-1" == returnValue:
|
65 |
if "-1" == returnValue:
|
| 62 |
raise Exception("Credit balance low.")
|
66 |
raise Exception("Credit balance low.")
|
| 63 |
|
67 |
|
| 64 |
elif "0" == returnValue:
|
68 |
elif "0" == returnValue:
|
| 65 |
raise Exception("Network or some other failure.")
|
69 |
raise Exception("Network or some other failure.")
|
| 66 |
|
70 |
|
| 67 |
return returnValue;
|
71 |
return returnValue;
|
| 68 |
|
72 |
|
| 69 |
def issueVoucher(username, password, userId, userEmail, amount):
|
73 |
def issueVoucher(userId, userEmail, amount):
|
| 70 |
pc = PromotionClient().get_client()
|
74 |
pc = PromotionClient().get_client()
|
| 71 |
voucher = pc.assignVoucher(userId, userEmail, VoucherType.SPICEDECK_MOBILE, amount)
|
75 |
voucher = pc.assignVoucher(userId, userEmail, VoucherType.SPICEDECK_MOBILE, amount)
|
| 72 |
isActivated = activateVoucher(username, password, voucher.voucherCode, voucher.userEmail);
|
76 |
isActivated = activateVoucher(voucher.voucherCode, voucher.userEmail);
|
| 73 |
if not isActivated:
|
77 |
if not isActivated:
|
| 74 |
raise Exception("Voucher could not get activated.");
|
78 |
raise Exception("Voucher could not get activated.");
|
| 75 |
return voucher.voucherCode
|
79 |
return voucher.voucherCode
|
| - |
|
80 |
|
| 76 |
def activateVoucher(username, password, voucherCode, userEmail):
|
81 |
def activateVoucher(voucherCode, userEmail):
|
| 77 |
params = "userid=" + username + "&password=" + password + "&cid=" + voucherCode + "&email=" + userEmail
|
82 |
params = "userid=" + username + "&password=" + password + "&cid=" + voucherCode + "&email=" + userEmail + "&expiry=" + "30-AUG-12"
|
| 78 |
returnValue = urllib2.urlopen(voucherActivationUrl + "?" + params).read()
|
83 |
returnValue = urllib2.urlopen(voucherActivationUrl + "?" + params).read()
|
| 79 |
if "1" == returnValue:
|
84 |
if "1" == returnValue:
|
| 80 |
return True;
|
85 |
return True;
|
| 81 |
elif "-1" == returnValue:
|
86 |
elif "-1" == returnValue:
|
| 82 |
raise Exception("Invalid voucher.")
|
87 |
raise Exception("Invalid voucher.")
|
| 83 |
elif "0" == returnValue:
|
88 |
elif "0" == returnValue:
|
| 84 |
raise Exception("Network or some other failure.")
|
89 |
raise Exception("Network or some other failure.")
|
| 85 |
return False
|
90 |
return False
|
| - |
|
91 |
|
| - |
|
92 |
def deactivateVoucher(voucherCode, reason):
|
| - |
|
93 |
params = "userid=" + username + "&password=" + password + "&cid=" + voucherCode + "&comment=" + reason
|
| - |
|
94 |
returnValue = urllib2.urlopen(voucherDeactivationUrl + "?" + params).read()
|
| - |
|
95 |
print returnValue
|
| - |
|
96 |
## 0#2#2#pankaj.kankar@shop2020.in
|
| - |
|
97 |
tokens = returnValue.split('#')
|
| - |
|
98 |
status = tokens[0]
|
| - |
|
99 |
actualAmount = int(tokens[1])
|
| - |
|
100 |
availableAmount = int(tokens[2])
|
| - |
|
101 |
email = tokens[3]
|
| - |
|
102 |
if "1" == status:
|
| - |
|
103 |
return True;
|
| - |
|
104 |
elif "0" == status:
|
| - |
|
105 |
raise Exception("Voucher could not be deactivated")
|
| - |
|
106 |
elif "-1" == status:
|
| - |
|
107 |
raise Exception("Network or some other failure.")
|
| - |
|
108 |
return False
|
| - |
|
109 |
|
| - |
|
110 |
|
| - |
|
111 |
def checkVoucherStatus(voucherCode):
|
| - |
|
112 |
params = "userid=" + username + "&password=" + password + "&cid=" + voucherCode
|
| - |
|
113 |
returnValue = urllib2.urlopen(voucherStatusUrl + "?" + params).read()
|
| - |
|
114 |
print returnValue
|
| - |
|
115 |
## ACTIVATE#2#2#pankaj.kankar@shop2020.in
|
| - |
|
116 |
## DEACTIVATED#2#2#pankaj.kankar@shop2020.in
|
| - |
|
117 |
## CONSUMED
|
| - |
|
118 |
## EXPIRED
|
| - |
|
119 |
if "-1" == returnValue:
|
| - |
|
120 |
raise Exception("Network or some other failure.")
|
| 86 |
|
121 |
else:
|
| - |
|
122 |
tokens = returnValue.split('#')
|
| - |
|
123 |
status = tokens[0]
|
| - |
|
124 |
actualAmount = int(tokens[1])
|
| - |
|
125 |
availableAmount = int(tokens[2])
|
| - |
|
126 |
email = tokens[3]
|
| 87 |
def sendEmail(email, amount, orderId, voucherCode):
|
127 |
def sendEmail(email, amount, orderId, voucherCode):
|
| 88 |
html = """
|
128 |
html = """
|
| 89 |
<html>
|
129 |
<html>
|
| 90 |
<body>
|
130 |
<body>
|
| 91 |
<div>
|
131 |
<div>
|
| Line 131... |
Line 171... |
| 131 |
metavar="HOST")
|
171 |
metavar="HOST")
|
| 132 |
(options, args) = parser.parse_args()
|
172 |
(options, args) = parser.parse_args()
|
| 133 |
if len(args) != 0:
|
173 |
if len(args) != 0:
|
| 134 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
174 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
| 135 |
issue_voucher_to_orders(options.days, options.hostname)
|
175 |
issue_voucher_to_orders(options.days, options.hostname)
|
| - |
|
176 |
#checkVoucherStatus('SHL1340973067027')
|
| - |
|
177 |
#deactivateVoucher('SHL1340973067027', 'Order not delivered')
|
| 136 |
|
178 |
|
| 137 |
if __name__ == '__main__':
|
179 |
if __name__ == '__main__':
|
| 138 |
main()
|
180 |
main()
|
| 139 |
|
181 |
|