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