Subversion Repositories SmartDukaan

Rev

Rev 3385 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1976 varun.gupt 1
#!/usr/bin/env python
2
#
3
# Autogenerated by Thrift
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 closeSession()'
25
  print '  void createPromotion(string name, string ruleExecutionSrc, i64 startOn, i64 endOn)'
26
  print '   getAllPromotions()'
27
  print '  Promotion getPromotionById(i64 promotionId)'
28
  print '  void generateCouponsForPromotion(i64 promotionId, string couponCode)'
29
  print '  Cart applyCoupon(string couponCode, i64 cartId)'
30
  print '  void trackCouponUsage(string couponCode, i64 transactionId, i64 userId)'
31
  print '  i64 getCouponUsageCountByUser(string couponCode, i64 userId)'
32
  print ''
33
  sys.exit(0)
34
 
35
pp = pprint.PrettyPrinter(indent = 2)
36
host = 'localhost'
37
port = 9090
38
uri = ''
39
framed = False
40
http = False
41
argi = 1
42
 
43
if sys.argv[argi] == '-h':
44
  parts = sys.argv[argi+1].split(':') 
45
  host = parts[0]
46
  port = int(parts[1])
47
  argi += 2
48
 
49
if sys.argv[argi] == '-u':
50
  url = urlparse(sys.argv[argi+1])
51
  parts = url[1].split(':') 
52
  host = parts[0]
53
  if len(parts) > 1:
54
    port = int(parts[1])
55
  else:
56
    port = 80
57
  uri = url[2]
58
  http = True
59
  argi += 2
60
 
61
if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
62
  framed = True
63
  argi += 1
64
 
65
cmd = sys.argv[argi]
66
args = sys.argv[argi+1:]
67
 
68
if http:
69
  transport = THttpClient.THttpClient(host, port, uri)
70
else:
71
  socket = TSocket.TSocket(host, port)
72
  if framed:
73
    transport = TTransport.TFramedTransport(socket)
74
  else:
75
    transport = TTransport.TBufferedTransport(socket)
76
protocol = TBinaryProtocol.TBinaryProtocol(transport)
77
client = PromotionService.Client(protocol)
78
transport.open()
79
 
80
if cmd == 'closeSession':
81
  if len(args) != 0:
82
    print 'closeSession requires 0 args'
83
    sys.exit(1)
84
  pp.pprint(client.closeSession())
85
 
86
elif cmd == 'createPromotion':
87
  if len(args) != 4:
88
    print 'createPromotion requires 4 args'
89
    sys.exit(1)
90
  pp.pprint(client.createPromotion(args[0],args[1],eval(args[2]),eval(args[3]),))
91
 
92
elif cmd == 'getAllPromotions':
93
  if len(args) != 0:
94
    print 'getAllPromotions requires 0 args'
95
    sys.exit(1)
96
  pp.pprint(client.getAllPromotions())
97
 
98
elif cmd == 'getPromotionById':
99
  if len(args) != 1:
100
    print 'getPromotionById requires 1 args'
101
    sys.exit(1)
102
  pp.pprint(client.getPromotionById(eval(args[0]),))
103
 
104
elif cmd == 'generateCouponsForPromotion':
105
  if len(args) != 2:
106
    print 'generateCouponsForPromotion requires 2 args'
107
    sys.exit(1)
108
  pp.pprint(client.generateCouponsForPromotion(eval(args[0]),args[1],))
109
 
110
elif cmd == 'applyCoupon':
111
  if len(args) != 2:
112
    print 'applyCoupon requires 2 args'
113
    sys.exit(1)
114
  pp.pprint(client.applyCoupon(args[0],eval(args[1]),))
115
 
116
elif cmd == 'trackCouponUsage':
117
  if len(args) != 3:
118
    print 'trackCouponUsage requires 3 args'
119
    sys.exit(1)
120
  pp.pprint(client.trackCouponUsage(args[0],eval(args[1]),eval(args[2]),))
121
 
122
elif cmd == 'getCouponUsageCountByUser':
123
  if len(args) != 2:
124
    print 'getCouponUsageCountByUser requires 2 args'
125
    sys.exit(1)
126
  pp.pprint(client.getCouponUsageCountByUser(args[0],eval(args[1]),))
127
 
128
transport.close()