| 1976 |
varun.gupt |
1 |
#!/usr/bin/env python
|
|
|
2 |
#
|
| 3431 |
rajveer |
3 |
# Autogenerated by Thrift Compiler (0.7.0)
|
| 1976 |
varun.gupt |
4 |
#
|
|
|
5 |
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
|
|
6 |
#
|
|
|
7 |
|
|
|
8 |
import sys
|
|
|
9 |
import pprint
|
|
|
10 |
from urlparse import urlparse
|
|
|
11 |
from thrift.transport import TTransport
|
|
|
12 |
from thrift.transport import TSocket
|
|
|
13 |
from thrift.transport import THttpClient
|
|
|
14 |
from thrift.protocol import TBinaryProtocol
|
|
|
15 |
|
|
|
16 |
import PromotionService
|
|
|
17 |
from ttypes import *
|
|
|
18 |
|
|
|
19 |
if len(sys.argv) <= 1 or sys.argv[1] == '--help':
|
|
|
20 |
print ''
|
|
|
21 |
print 'Usage: ' + sys.argv[0] + ' [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
|
|
|
22 |
print ''
|
|
|
23 |
print 'Functions:'
|
|
|
24 |
print ' void createPromotion(string name, string ruleExecutionSrc, i64 startOn, i64 endOn)'
|
| 7746 |
amit.gupta |
25 |
print ' i64 removeAllCouponsByPromotionId(i64 promotionId)'
|
| 6301 |
amit.gupta |
26 |
print ' Coupon getCoupon(string couponCode)'
|
|
|
27 |
print ' bool isGiftVoucher(string couponCode)'
|
| 6356 |
amit.gupta |
28 |
print ' bool isCodApplicable(string couponCode)'
|
| 1976 |
varun.gupt |
29 |
print ' getAllPromotions()'
|
|
|
30 |
print ' Promotion getPromotionById(i64 promotionId)'
|
|
|
31 |
print ' void generateCouponsForPromotion(i64 promotionId, string couponCode)'
|
|
|
32 |
print ' Cart applyCoupon(string couponCode, i64 cartId)'
|
| 6736 |
amit.gupta |
33 |
print ' getEmiDiscount(i64 cartId)'
|
| 6433 |
anupam.sin |
34 |
print ' applyRechargeCoupon(string couponCode, i64 totalAmount, i64 userId)'
|
| 1976 |
varun.gupt |
35 |
print ' void trackCouponUsage(string couponCode, i64 transactionId, i64 userId)'
|
|
|
36 |
print ' i64 getCouponUsageCountByUser(string couponCode, i64 userId)'
|
| 6497 |
amit.gupta |
37 |
print ' getActiveCodes(i64 promotionId)'
|
|
|
38 |
print ' void deleteCoupon(string couponCode)'
|
| 7092 |
amit.gupta |
39 |
print ' getAllCouponsByPromotionId(i64 promotionId)'
|
| 3385 |
varun.gupt |
40 |
print ' getActiveCoupons()'
|
| 8707 |
manish.sha |
41 |
print ' string createCoupon(i64 promotionId, i64 couponCategory, string couponCode, string arguments, bool isCod, string prefix)'
|
| 3385 |
varun.gupt |
42 |
print ' i64 getSuccessfulPaymentCountForCoupon(string couponCode)'
|
|
|
43 |
print ' string getRuleDocString(string ruleName)'
|
| 4189 |
varun.gupt |
44 |
print ' getItemDiscountMap( itemIds)'
|
| 4494 |
varun.gupt |
45 |
print ' getDiscountsForEntity(i64 entityId)'
|
| 5469 |
rajveer |
46 |
print ' void addVoucher(Voucher voucher)'
|
|
|
47 |
print ' Voucher assignVoucher(i64 userId, string userEmail, VoucherType voucherType, i64 amount)'
|
|
|
48 |
print ' bool markVoucherAsRedeemed(string voucherCode, i64 redeemedOn)'
|
| 1976 |
varun.gupt |
49 |
print ''
|
|
|
50 |
sys.exit(0)
|
|
|
51 |
|
|
|
52 |
pp = pprint.PrettyPrinter(indent = 2)
|
|
|
53 |
host = 'localhost'
|
|
|
54 |
port = 9090
|
|
|
55 |
uri = ''
|
|
|
56 |
framed = False
|
|
|
57 |
http = False
|
|
|
58 |
argi = 1
|
|
|
59 |
|
|
|
60 |
if sys.argv[argi] == '-h':
|
| 3431 |
rajveer |
61 |
parts = sys.argv[argi+1].split(':')
|
| 1976 |
varun.gupt |
62 |
host = parts[0]
|
|
|
63 |
port = int(parts[1])
|
|
|
64 |
argi += 2
|
|
|
65 |
|
|
|
66 |
if sys.argv[argi] == '-u':
|
|
|
67 |
url = urlparse(sys.argv[argi+1])
|
| 3431 |
rajveer |
68 |
parts = url[1].split(':')
|
| 1976 |
varun.gupt |
69 |
host = parts[0]
|
|
|
70 |
if len(parts) > 1:
|
|
|
71 |
port = int(parts[1])
|
|
|
72 |
else:
|
|
|
73 |
port = 80
|
|
|
74 |
uri = url[2]
|
| 3431 |
rajveer |
75 |
if url[4]:
|
|
|
76 |
uri += '?%s' % url[4]
|
| 1976 |
varun.gupt |
77 |
http = True
|
|
|
78 |
argi += 2
|
|
|
79 |
|
|
|
80 |
if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
|
|
|
81 |
framed = True
|
|
|
82 |
argi += 1
|
|
|
83 |
|
|
|
84 |
cmd = sys.argv[argi]
|
|
|
85 |
args = sys.argv[argi+1:]
|
|
|
86 |
|
|
|
87 |
if http:
|
|
|
88 |
transport = THttpClient.THttpClient(host, port, uri)
|
|
|
89 |
else:
|
|
|
90 |
socket = TSocket.TSocket(host, port)
|
|
|
91 |
if framed:
|
|
|
92 |
transport = TTransport.TFramedTransport(socket)
|
|
|
93 |
else:
|
|
|
94 |
transport = TTransport.TBufferedTransport(socket)
|
|
|
95 |
protocol = TBinaryProtocol.TBinaryProtocol(transport)
|
|
|
96 |
client = PromotionService.Client(protocol)
|
|
|
97 |
transport.open()
|
|
|
98 |
|
| 3431 |
rajveer |
99 |
if cmd == 'createPromotion':
|
| 1976 |
varun.gupt |
100 |
if len(args) != 4:
|
|
|
101 |
print 'createPromotion requires 4 args'
|
|
|
102 |
sys.exit(1)
|
|
|
103 |
pp.pprint(client.createPromotion(args[0],args[1],eval(args[2]),eval(args[3]),))
|
|
|
104 |
|
| 7746 |
amit.gupta |
105 |
elif cmd == 'removeAllCouponsByPromotionId':
|
|
|
106 |
if len(args) != 1:
|
|
|
107 |
print 'removeAllCouponsByPromotionId requires 1 args'
|
|
|
108 |
sys.exit(1)
|
|
|
109 |
pp.pprint(client.removeAllCouponsByPromotionId(eval(args[0]),))
|
|
|
110 |
|
| 6301 |
amit.gupta |
111 |
elif cmd == 'getCoupon':
|
|
|
112 |
if len(args) != 1:
|
|
|
113 |
print 'getCoupon requires 1 args'
|
|
|
114 |
sys.exit(1)
|
|
|
115 |
pp.pprint(client.getCoupon(args[0],))
|
|
|
116 |
|
|
|
117 |
elif cmd == 'isGiftVoucher':
|
|
|
118 |
if len(args) != 1:
|
|
|
119 |
print 'isGiftVoucher requires 1 args'
|
|
|
120 |
sys.exit(1)
|
|
|
121 |
pp.pprint(client.isGiftVoucher(args[0],))
|
|
|
122 |
|
| 6356 |
amit.gupta |
123 |
elif cmd == 'isCodApplicable':
|
|
|
124 |
if len(args) != 1:
|
|
|
125 |
print 'isCodApplicable requires 1 args'
|
|
|
126 |
sys.exit(1)
|
|
|
127 |
pp.pprint(client.isCodApplicable(args[0],))
|
|
|
128 |
|
| 1976 |
varun.gupt |
129 |
elif cmd == 'getAllPromotions':
|
|
|
130 |
if len(args) != 0:
|
|
|
131 |
print 'getAllPromotions requires 0 args'
|
|
|
132 |
sys.exit(1)
|
|
|
133 |
pp.pprint(client.getAllPromotions())
|
|
|
134 |
|
|
|
135 |
elif cmd == 'getPromotionById':
|
|
|
136 |
if len(args) != 1:
|
|
|
137 |
print 'getPromotionById requires 1 args'
|
|
|
138 |
sys.exit(1)
|
|
|
139 |
pp.pprint(client.getPromotionById(eval(args[0]),))
|
|
|
140 |
|
|
|
141 |
elif cmd == 'generateCouponsForPromotion':
|
|
|
142 |
if len(args) != 2:
|
|
|
143 |
print 'generateCouponsForPromotion requires 2 args'
|
|
|
144 |
sys.exit(1)
|
|
|
145 |
pp.pprint(client.generateCouponsForPromotion(eval(args[0]),args[1],))
|
|
|
146 |
|
|
|
147 |
elif cmd == 'applyCoupon':
|
|
|
148 |
if len(args) != 2:
|
|
|
149 |
print 'applyCoupon requires 2 args'
|
|
|
150 |
sys.exit(1)
|
|
|
151 |
pp.pprint(client.applyCoupon(args[0],eval(args[1]),))
|
|
|
152 |
|
| 6736 |
amit.gupta |
153 |
elif cmd == 'getEmiDiscount':
|
|
|
154 |
if len(args) != 1:
|
|
|
155 |
print 'getEmiDiscount requires 1 args'
|
|
|
156 |
sys.exit(1)
|
|
|
157 |
pp.pprint(client.getEmiDiscount(eval(args[0]),))
|
|
|
158 |
|
| 6433 |
anupam.sin |
159 |
elif cmd == 'applyRechargeCoupon':
|
|
|
160 |
if len(args) != 3:
|
|
|
161 |
print 'applyRechargeCoupon requires 3 args'
|
|
|
162 |
sys.exit(1)
|
|
|
163 |
pp.pprint(client.applyRechargeCoupon(args[0],eval(args[1]),eval(args[2]),))
|
|
|
164 |
|
| 1976 |
varun.gupt |
165 |
elif cmd == 'trackCouponUsage':
|
|
|
166 |
if len(args) != 3:
|
|
|
167 |
print 'trackCouponUsage requires 3 args'
|
|
|
168 |
sys.exit(1)
|
|
|
169 |
pp.pprint(client.trackCouponUsage(args[0],eval(args[1]),eval(args[2]),))
|
|
|
170 |
|
|
|
171 |
elif cmd == 'getCouponUsageCountByUser':
|
|
|
172 |
if len(args) != 2:
|
|
|
173 |
print 'getCouponUsageCountByUser requires 2 args'
|
|
|
174 |
sys.exit(1)
|
|
|
175 |
pp.pprint(client.getCouponUsageCountByUser(args[0],eval(args[1]),))
|
|
|
176 |
|
| 6497 |
amit.gupta |
177 |
elif cmd == 'getActiveCodes':
|
|
|
178 |
if len(args) != 1:
|
|
|
179 |
print 'getActiveCodes requires 1 args'
|
|
|
180 |
sys.exit(1)
|
|
|
181 |
pp.pprint(client.getActiveCodes(eval(args[0]),))
|
|
|
182 |
|
|
|
183 |
elif cmd == 'deleteCoupon':
|
|
|
184 |
if len(args) != 1:
|
|
|
185 |
print 'deleteCoupon requires 1 args'
|
|
|
186 |
sys.exit(1)
|
|
|
187 |
pp.pprint(client.deleteCoupon(args[0],))
|
|
|
188 |
|
| 7092 |
amit.gupta |
189 |
elif cmd == 'getAllCouponsByPromotionId':
|
|
|
190 |
if len(args) != 1:
|
|
|
191 |
print 'getAllCouponsByPromotionId requires 1 args'
|
|
|
192 |
sys.exit(1)
|
|
|
193 |
pp.pprint(client.getAllCouponsByPromotionId(eval(args[0]),))
|
|
|
194 |
|
| 3385 |
varun.gupt |
195 |
elif cmd == 'getActiveCoupons':
|
|
|
196 |
if len(args) != 0:
|
|
|
197 |
print 'getActiveCoupons requires 0 args'
|
|
|
198 |
sys.exit(1)
|
|
|
199 |
pp.pprint(client.getActiveCoupons())
|
|
|
200 |
|
| 6250 |
amit.gupta |
201 |
elif cmd == 'createCoupon':
|
| 8707 |
manish.sha |
202 |
if len(args) != 6:
|
|
|
203 |
print 'createCoupon requires 6 args'
|
| 6250 |
amit.gupta |
204 |
sys.exit(1)
|
| 8707 |
manish.sha |
205 |
pp.pprint(client.createCoupon(eval(args[0]),eval(args[1]),args[2],args[3],eval(args[4]),args[5],))
|
| 6250 |
amit.gupta |
206 |
|
| 3385 |
varun.gupt |
207 |
elif cmd == 'getSuccessfulPaymentCountForCoupon':
|
|
|
208 |
if len(args) != 1:
|
|
|
209 |
print 'getSuccessfulPaymentCountForCoupon requires 1 args'
|
|
|
210 |
sys.exit(1)
|
|
|
211 |
pp.pprint(client.getSuccessfulPaymentCountForCoupon(args[0],))
|
|
|
212 |
|
|
|
213 |
elif cmd == 'getRuleDocString':
|
|
|
214 |
if len(args) != 1:
|
|
|
215 |
print 'getRuleDocString requires 1 args'
|
|
|
216 |
sys.exit(1)
|
|
|
217 |
pp.pprint(client.getRuleDocString(args[0],))
|
|
|
218 |
|
| 4189 |
varun.gupt |
219 |
elif cmd == 'getItemDiscountMap':
|
|
|
220 |
if len(args) != 1:
|
|
|
221 |
print 'getItemDiscountMap requires 1 args'
|
|
|
222 |
sys.exit(1)
|
|
|
223 |
pp.pprint(client.getItemDiscountMap(eval(args[0]),))
|
|
|
224 |
|
| 4494 |
varun.gupt |
225 |
elif cmd == 'getDiscountsForEntity':
|
|
|
226 |
if len(args) != 1:
|
|
|
227 |
print 'getDiscountsForEntity requires 1 args'
|
|
|
228 |
sys.exit(1)
|
|
|
229 |
pp.pprint(client.getDiscountsForEntity(eval(args[0]),))
|
|
|
230 |
|
| 5469 |
rajveer |
231 |
elif cmd == 'addVoucher':
|
|
|
232 |
if len(args) != 1:
|
|
|
233 |
print 'addVoucher requires 1 args'
|
|
|
234 |
sys.exit(1)
|
|
|
235 |
pp.pprint(client.addVoucher(eval(args[0]),))
|
|
|
236 |
|
|
|
237 |
elif cmd == 'assignVoucher':
|
|
|
238 |
if len(args) != 4:
|
|
|
239 |
print 'assignVoucher requires 4 args'
|
|
|
240 |
sys.exit(1)
|
|
|
241 |
pp.pprint(client.assignVoucher(eval(args[0]),args[1],eval(args[2]),eval(args[3]),))
|
|
|
242 |
|
|
|
243 |
elif cmd == 'markVoucherAsRedeemed':
|
|
|
244 |
if len(args) != 2:
|
|
|
245 |
print 'markVoucherAsRedeemed requires 2 args'
|
|
|
246 |
sys.exit(1)
|
|
|
247 |
pp.pprint(client.markVoucherAsRedeemed(args[0],eval(args[1]),))
|
|
|
248 |
|
| 3431 |
rajveer |
249 |
else:
|
|
|
250 |
print 'Unrecognized method %s' % cmd
|
|
|
251 |
sys.exit(1)
|
|
|
252 |
|
| 1976 |
varun.gupt |
253 |
transport.close()
|