| Line 6... |
Line 6... |
| 6 |
|
6 |
|
| 7 |
@author: Rajveer
|
7 |
@author: Rajveer
|
| 8 |
'''
|
8 |
'''
|
| 9 |
|
9 |
|
| 10 |
import datetime
|
10 |
import datetime
|
| - |
|
11 |
from datetime import date
|
| 11 |
import optparse
|
12 |
import optparse
|
| 12 |
import sys
|
13 |
import sys
|
| 13 |
import urllib2
|
14 |
import urllib2
|
| 14 |
from string import Template
|
15 |
from string import Template
|
| 15 |
from shop2020.clients.HelperClient import HelperClient
|
16 |
from shop2020.clients.HelperClient import HelperClient
|
| Line 30... |
Line 31... |
| 30 |
voucherDeactivationUrl = "http://www.spicedeck.com/coupondeact.sdesk"
|
31 |
voucherDeactivationUrl = "http://www.spicedeck.com/coupondeact.sdesk"
|
| 31 |
voucherStatusUrl = "http://www.spicedeck.com/couponstatus.sdesk"
|
32 |
voucherStatusUrl = "http://www.spicedeck.com/couponstatus.sdesk"
|
| 32 |
username = "saholic"
|
33 |
username = "saholic"
|
| 33 |
password = "abc1234"
|
34 |
password = "abc1234"
|
| 34 |
|
35 |
|
| 35 |
def issue_voucher_to_orders(days, db_hostname):
|
36 |
def issue_voucher_to_orders(db_hostname):
|
| 36 |
DataService.initialize(db_hostname=db_hostname, echoOn=True)
|
37 |
DataService.initialize(db_hostname=db_hostname, echoOn=True)
|
| 37 |
current_time = datetime.datetime.now()
|
- |
|
| 38 |
to_datetime = datetime.datetime(current_time.year, current_time.month, current_time.day)
|
- |
|
| 39 |
to_datetime = to_datetime - datetime.timedelta(days-1)
|
- |
|
| 40 |
vouchers = RechargeVoucherTracker.query.filter_by(voucherIssued=False).all()
|
38 |
vouchers = RechargeVoucherTracker.query.filter_by(voucherIssued=False).all()
|
| 41 |
for voucher in vouchers:
|
39 |
for voucher in vouchers:
|
| 42 |
order = voucher.order
|
40 |
order = voucher.order
|
| 43 |
if order.status == OrderStatus.DELIVERY_SUCCESS and order.delivery_timestamp <= to_datetime:
|
41 |
if order.status == OrderStatus.DELIVERY_SUCCESS:
|
| 44 |
storeVoucher(voucher.amount)
|
42 |
storeVoucher(voucher.amount)
|
| 45 |
coupon = issueVoucher(order.customer_id, order.customer_email, voucher.amount)
|
43 |
coupon = issueVoucher(order.customer_id, order.customer_email, voucher.amount)
|
| 46 |
voucher.issuedOn = current_time
|
44 |
voucher.issuedOn = datetime.datetime.now()
|
| 47 |
voucher.voucherIssued = True
|
45 |
voucher.voucherIssued = True
|
| 48 |
voucher.voucherCode = coupon
|
46 |
voucher.voucherCode = coupon
|
| 49 |
#sendEmail(order.customer_email, voucher.amount, order.id, coupon)
|
47 |
#sendEmail(order.customer_email, voucher.amount, order.id, coupon)
|
| 50 |
session.commit()
|
48 |
session.commit()
|
| 51 |
|
49 |
|
| Line 77... |
Line 75... |
| 77 |
if not isActivated:
|
75 |
if not isActivated:
|
| 78 |
raise Exception("Voucher could not get activated.");
|
76 |
raise Exception("Voucher could not get activated.");
|
| 79 |
return voucher.voucherCode
|
77 |
return voucher.voucherCode
|
| 80 |
|
78 |
|
| 81 |
def activateVoucher(voucherCode, userEmail):
|
79 |
def activateVoucher(voucherCode, userEmail):
|
| - |
|
80 |
today = date.today() + datetime.timedelta(365/4)
|
| 82 |
params = "userid=" + username + "&password=" + password + "&cid=" + voucherCode + "&email=" + userEmail + "&expiry=" + "30-AUG-12"
|
81 |
params = "userid=" + username + "&password=" + password + "&cid=" + voucherCode + "&email=" + userEmail + "&expiry=" + today.strftime('%d-%b-%y')
|
| 83 |
returnValue = urllib2.urlopen(voucherActivationUrl + "?" + params).read()
|
82 |
returnValue = urllib2.urlopen(voucherActivationUrl + "?" + params).read()
|
| 84 |
if "1" == returnValue:
|
83 |
if "1" == returnValue:
|
| 85 |
return True;
|
84 |
return True;
|
| 86 |
elif "-1" == returnValue:
|
85 |
elif "-1" == returnValue:
|
| 87 |
raise Exception("Invalid voucher.")
|
86 |
raise Exception("Invalid voucher.")
|
| Line 159... |
Line 158... |
| 159 |
print e
|
158 |
print e
|
| 160 |
|
159 |
|
| 161 |
|
160 |
|
| 162 |
def main():
|
161 |
def main():
|
| 163 |
parser = optparse.OptionParser()
|
162 |
parser = optparse.OptionParser()
|
| 164 |
parser.add_option("-d", "--days", dest="days",
|
163 |
# parser.add_option("-d", "--days", dest="days",
|
| 165 |
default=5, type="int",
|
164 |
# default=5, type="int",
|
| 166 |
help="issue voucher to the delivered orders before NUM days",
|
165 |
# help="issue voucher to the delivered orders before NUM days",
|
| 167 |
metavar="NUM")
|
166 |
# metavar="NUM")
|
| 168 |
parser.add_option("-H", "--host", dest="hostname",
|
167 |
parser.add_option("-H", "--host", dest="hostname",
|
| 169 |
default="localhost",
|
168 |
default="localhost",
|
| 170 |
type="string", help="The HOST where the DB server is running",
|
169 |
type="string", help="The HOST where the DB server is running",
|
| 171 |
metavar="HOST")
|
170 |
metavar="HOST")
|
| 172 |
(options, args) = parser.parse_args()
|
171 |
(options, args) = parser.parse_args()
|
| 173 |
if len(args) != 0:
|
172 |
if len(args) != 0:
|
| 174 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
173 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
| 175 |
issue_voucher_to_orders(options.days, options.hostname)
|
174 |
#issue_voucher_to_orders(options.days, options.hostname)
|
| - |
|
175 |
issue_voucher_to_orders(options.hostname)
|
| 176 |
#checkVoucherStatus('SHL1340973067027')
|
176 |
#checkVoucherStatus('SHL1340973067027')
|
| 177 |
#deactivateVoucher('SHL1340973067027', 'Order not delivered')
|
177 |
#deactivateVoucher('SHL1340973067027', 'Order not delivered')
|
| 178 |
|
178 |
|
| 179 |
if __name__ == '__main__':
|
179 |
if __name__ == '__main__':
|
| 180 |
main()
|
180 |
main()
|
| 181 |
|
181 |
|