Subversion Repositories SmartDukaan

Rev

Rev 6730 | Rev 7092 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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