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