| 13804 |
amit.gupta |
1 |
'''
|
|
|
2 |
Created on Feb 12, 2015
|
|
|
3 |
|
|
|
4 |
@author: amit
|
|
|
5 |
'''
|
|
|
6 |
from dtr import main
|
| 14427 |
amit.gupta |
7 |
from dtr.storage import Mongo, Mysql
|
| 13804 |
amit.gupta |
8 |
import falcon
|
|
|
9 |
import json
|
| 14014 |
amit.gupta |
10 |
import urlparse
|
| 15229 |
amit.gupta |
11 |
import re
|
| 13804 |
amit.gupta |
12 |
class StoreOrder():
|
|
|
13 |
def on_post(self, req, resp):
|
|
|
14 |
|
|
|
15 |
try:
|
|
|
16 |
string1 = req.stream.read()
|
|
|
17 |
req_json = json.loads(string1, encoding='utf-8')
|
|
|
18 |
except ValueError:
|
|
|
19 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
20 |
'Malformed JSON',
|
|
|
21 |
'Could not decode the request body. The '
|
|
|
22 |
'JSON was incorrect.')
|
|
|
23 |
|
|
|
24 |
store = main.getStore(int(req_json['sourceId']))
|
|
|
25 |
result = store.parseOrderRawHtml(int(req_json['orderId']), req_json['subTagId'], int(req_json['userId']), req_json['rawHtml'], req_json['orderSuccessUrl'])
|
|
|
26 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
27 |
|
|
|
28 |
def on_get(self, req, resp, userId):
|
|
|
29 |
page = req.get_param_as_int("page")
|
|
|
30 |
window = req.get_param_as_int("window")
|
| 14003 |
amit.gupta |
31 |
string1 = req.get_param("searchMap")
|
| 14004 |
amit.gupta |
32 |
searchMap={}
|
| 14006 |
amit.gupta |
33 |
if string1 is None or string1 == "":
|
| 14007 |
amit.gupta |
34 |
pass
|
|
|
35 |
else:
|
| 14006 |
amit.gupta |
36 |
try:
|
| 14007 |
amit.gupta |
37 |
searchMap = json.loads(string1, encoding='utf-8')
|
| 14006 |
amit.gupta |
38 |
except:
|
|
|
39 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
40 |
'Malformed JSON',
|
|
|
41 |
'Could not decode the request body. The '
|
|
|
42 |
'JSON was incorrect.')
|
| 14003 |
amit.gupta |
43 |
result = Mongo.getMerchantOrdersByUser(int(userId), page, window, searchMap)
|
| 13868 |
amit.gupta |
44 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
45 |
|
| 14352 |
amit.gupta |
46 |
class Orders():
|
|
|
47 |
def on_get(self, req, resp):
|
|
|
48 |
page = req.get_param_as_int("page")
|
|
|
49 |
window = req.get_param_as_int("window")
|
|
|
50 |
string1 = req.get_param("searchMap")
|
|
|
51 |
searchMap={}
|
|
|
52 |
if string1 is None or string1 == "":
|
|
|
53 |
pass
|
|
|
54 |
else:
|
|
|
55 |
try:
|
|
|
56 |
searchMap = json.loads(string1, encoding='utf-8')
|
|
|
57 |
except:
|
|
|
58 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
59 |
'Malformed JSON',
|
|
|
60 |
'Could not decode the request body. The '
|
|
|
61 |
'JSON was incorrect.')
|
|
|
62 |
result = Mongo.getMerchantOrdersByUser(None, page, window, searchMap)
|
|
|
63 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
64 |
|
| 13868 |
amit.gupta |
65 |
class Track():
|
| 13939 |
amit.gupta |
66 |
def on_post(self, req, resp, userId):
|
| 13868 |
amit.gupta |
67 |
try:
|
| 14013 |
amit.gupta |
68 |
string1 = req.stream.read()
|
| 14014 |
amit.gupta |
69 |
req_obj = urlparse.parse_qs(string1)
|
| 14013 |
amit.gupta |
70 |
except ValueError:
|
|
|
71 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
72 |
'Malformed JSON',
|
|
|
73 |
'Could not decode the request body. The '
|
|
|
74 |
'JSON was incorrect.')
|
|
|
75 |
try:
|
| 13927 |
amit.gupta |
76 |
store = main.getStore(req.get_param_as_int("storeId"))
|
|
|
77 |
if req.get_param_as_int("storeId") == 1:
|
| 14015 |
amit.gupta |
78 |
result = store.trackOrdersForUser(int(userId),req_obj['url'][0],req_obj['html'][0])
|
| 13927 |
amit.gupta |
79 |
resp.body = json.dumps({'result':result}, encoding='utf-8')
|
|
|
80 |
else:
|
|
|
81 |
resp.body = json.dumps({'result':'NOT_IMPLEMENTED'}, encoding='utf-8')
|
| 15791 |
manish.sha |
82 |
'''
|
|
|
83 |
elif req.get_param_as_int("storeId") == 7:
|
|
|
84 |
if 'myprofile' in req_obj['url'][0]:
|
|
|
85 |
result = store.parseMyProfileForEmailId(int(userId),req_obj['url'][0],req_obj['html'][0])
|
|
|
86 |
else:
|
|
|
87 |
result = store.parseMyOrdersForEmailId(int(userId),req_obj['url'][0],req_obj['html'][0])
|
|
|
88 |
resp.body = json.dumps({'result':result}, encoding='utf-8')
|
|
|
89 |
'''
|
| 13927 |
amit.gupta |
90 |
except:
|
|
|
91 |
resp.body = json.dumps({'result':'PARSE_ERROR'}, encoding='utf-8')
|
| 14087 |
amit.gupta |
92 |
|
| 14096 |
amit.gupta |
93 |
print "Returned from track POST", resp.body
|
|
|
94 |
resp.body = json.dumps({'result':'PARSE_ERROR'}, encoding='utf-8')
|
|
|
95 |
|
| 13868 |
amit.gupta |
96 |
|
| 13939 |
amit.gupta |
97 |
def on_get(self, req, resp, userId):
|
| 13868 |
amit.gupta |
98 |
try:
|
|
|
99 |
storeId = req.get_param_as_int("storeId")
|
| 13939 |
amit.gupta |
100 |
result = main.getStore(storeId).getTrackingUrls(int(userId))
|
| 13887 |
amit.gupta |
101 |
resp.body = json.dumps({'result':result}, encoding='utf-8')
|
| 13868 |
amit.gupta |
102 |
except ValueError:
|
|
|
103 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
104 |
'Malformed JSON',
|
|
|
105 |
'Could not decode the request body. The '
|
|
|
106 |
'JSON was incorrect.')
|
|
|
107 |
|
| 13927 |
amit.gupta |
108 |
class Refunds():
|
| 13990 |
amit.gupta |
109 |
def on_get(self, req, resp, userId):
|
| 13927 |
amit.gupta |
110 |
try:
|
|
|
111 |
page = req.get_param_as_int("page")
|
|
|
112 |
window = req.get_param_as_int("window")
|
| 13990 |
amit.gupta |
113 |
result = Mongo.getRefunds(int(userId),page,window)
|
| 13927 |
amit.gupta |
114 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
115 |
except ValueError:
|
|
|
116 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
117 |
'Malformed JSON',
|
|
|
118 |
'Could not decode the request body. The '
|
|
|
119 |
'JSON was incorrect.')
|
|
|
120 |
|
| 14427 |
amit.gupta |
121 |
class Transactions():
|
|
|
122 |
def on_get(self, req, resp):
|
|
|
123 |
try:
|
|
|
124 |
page = req.get_param_as_int("page")
|
|
|
125 |
window = req.get_param_as_int("window")
|
| 14725 |
amit.gupta |
126 |
user = req.get_param("user")
|
|
|
127 |
status = req.get_param("status")
|
| 15731 |
amit.gupta |
128 |
source = req.get_param("source")
|
| 14725 |
amit.gupta |
129 |
if user == "" :
|
|
|
130 |
user = None
|
|
|
131 |
if status == "" :
|
|
|
132 |
status = None
|
| 15731 |
amit.gupta |
133 |
result = Mysql.getOrders(page, window,status,user,source)
|
| 14427 |
amit.gupta |
134 |
resp.body = result
|
|
|
135 |
resp.content_type = 'text/html'
|
|
|
136 |
except ValueError:
|
|
|
137 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
138 |
'Malformed JSON',
|
|
|
139 |
'Could not decode the request body. The '
|
|
|
140 |
'JSON was incorrect.')
|
| 15081 |
amit.gupta |
141 |
|
|
|
142 |
class SnapShot():
|
|
|
143 |
def on_get(self, req, resp):
|
|
|
144 |
try:
|
|
|
145 |
resp.content_type = 'text/html'
|
|
|
146 |
user = req.get_param_as_int("user")
|
|
|
147 |
file = req.get_param("file")
|
|
|
148 |
if file is not None:
|
|
|
149 |
#fetch the page and return html
|
|
|
150 |
with open ("/AmazonTrack/User%d/%s"%(user, file), "r") as myfile:
|
|
|
151 |
resp.body=myfile.read()
|
|
|
152 |
else:
|
|
|
153 |
#return user specific urls
|
|
|
154 |
resp.body=getUserUrls(user)
|
|
|
155 |
except ValueError:
|
|
|
156 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
157 |
'Malformed JSON',
|
|
|
158 |
'Could not decode the request body. The '
|
|
|
159 |
'JSON was incorrect.')
|
|
|
160 |
|
|
|
161 |
def getUserUrls(user):
|
|
|
162 |
pass
|
| 14427 |
amit.gupta |
163 |
|
|
|
164 |
class RawHtml():
|
|
|
165 |
def on_get(self, req, resp, orderId):
|
|
|
166 |
try:
|
|
|
167 |
result = Mysql.getOrderHtml(orderId)
|
| 15544 |
amit.gupta |
168 |
if req.get_param("show") is None:
|
|
|
169 |
result = re.subn(r'(src|href|style)=\s?(\'|").*?\2(?s)', '', re.subn(r'<(script|style).*?</\1>(?s)', '', result)[0])[0]
|
| 14427 |
amit.gupta |
170 |
resp.body = result
|
|
|
171 |
resp.content_type = 'text/html'
|
|
|
172 |
except ValueError:
|
|
|
173 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
174 |
'Malformed JSON',
|
|
|
175 |
'Could not decode the request body. The '
|
|
|
176 |
'JSON was incorrect.')
|
|
|
177 |
|
| 13927 |
amit.gupta |
178 |
class PendingRefunds():
|
|
|
179 |
def on_get(self, req, resp,userId):
|
|
|
180 |
try:
|
|
|
181 |
result = Mongo.getPendingRefunds(int(userId))
|
|
|
182 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
183 |
except ValueError:
|
|
|
184 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
185 |
'Malformed JSON',
|
|
|
186 |
'Could not decode the request body. The '
|
| 14671 |
amit.gupta |
187 |
'JSON was incorrect.')
|
|
|
188 |
|
|
|
189 |
class PendingCashBacks():
|
|
|
190 |
def on_get(self, req, resp,userId):
|
|
|
191 |
try:
|
|
|
192 |
result = Mongo.getPendingCashbacks(int(userId))
|
|
|
193 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
194 |
except ValueError:
|
|
|
195 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
196 |
'Malformed JSON',
|
|
|
197 |
'Could not decode the request body. The '
|
| 13927 |
amit.gupta |
198 |
'JSON was incorrect.')
|