| 13572 |
kshitij.so |
1 |
import json
|
| 13582 |
amit.gupta |
2 |
from dtr import main
|
| 13629 |
kshitij.so |
3 |
from dtr.storage import Mongo
|
|
|
4 |
from bson import json_util
|
| 13827 |
kshitij.so |
5 |
import falcon
|
| 14046 |
kshitij.so |
6 |
from dtr.utils import FetchLivePrices, DealSheet as X_DealSheet, \
|
|
|
7 |
UserSpecificDeals
|
| 13572 |
kshitij.so |
8 |
|
|
|
9 |
|
|
|
10 |
class CategoryDiscountInfo(object):
|
|
|
11 |
|
|
|
12 |
def on_get(self, req, resp):
|
|
|
13 |
|
| 13629 |
kshitij.so |
14 |
result = Mongo.getAllCategoryDiscount()
|
|
|
15 |
json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
|
|
|
16 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13572 |
kshitij.so |
17 |
|
|
|
18 |
def on_post(self, req, resp):
|
|
|
19 |
try:
|
|
|
20 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
21 |
except ValueError:
|
|
|
22 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
23 |
'Malformed JSON',
|
|
|
24 |
'Could not decode the request body. The '
|
|
|
25 |
'JSON was incorrect.')
|
|
|
26 |
|
|
|
27 |
result = Mongo.addCategoryDiscount(result_json)
|
|
|
28 |
resp.body = json.dumps(result, encoding='utf-8')
|
| 13969 |
kshitij.so |
29 |
|
|
|
30 |
def on_put(self, req, resp, _id):
|
| 13970 |
kshitij.so |
31 |
try:
|
|
|
32 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
33 |
except ValueError:
|
|
|
34 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
35 |
'Malformed JSON',
|
|
|
36 |
'Could not decode the request body. The '
|
|
|
37 |
'JSON was incorrect.')
|
|
|
38 |
|
|
|
39 |
result = Mongo.updateCategoryDiscount(result_json, _id)
|
|
|
40 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
41 |
|
| 13966 |
kshitij.so |
42 |
|
| 13969 |
kshitij.so |
43 |
|
| 13572 |
kshitij.so |
44 |
class SkuSchemeDetails(object):
|
|
|
45 |
|
|
|
46 |
def on_get(self, req, resp):
|
| 13629 |
kshitij.so |
47 |
|
| 14070 |
kshitij.so |
48 |
offset = req.get_param_as_int("offset")
|
|
|
49 |
limit = req.get_param_as_int("limit")
|
|
|
50 |
|
|
|
51 |
result = Mongo.getAllSkuWiseSchemeDetails(offset, limit)
|
| 13629 |
kshitij.so |
52 |
json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
|
|
|
53 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13572 |
kshitij.so |
54 |
|
|
|
55 |
|
|
|
56 |
def on_post(self, req, resp):
|
|
|
57 |
|
|
|
58 |
try:
|
|
|
59 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
60 |
except ValueError:
|
|
|
61 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
62 |
'Malformed JSON',
|
|
|
63 |
'Could not decode the request body. The '
|
|
|
64 |
'JSON was incorrect.')
|
|
|
65 |
|
|
|
66 |
result = Mongo.addSchemeDetailsForSku(result_json)
|
|
|
67 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
68 |
|
|
|
69 |
class SkuDiscountInfo():
|
|
|
70 |
|
|
|
71 |
def on_get(self, req, resp):
|
| 13629 |
kshitij.so |
72 |
|
| 13970 |
kshitij.so |
73 |
offset = req.get_param_as_int("offset")
|
|
|
74 |
limit = req.get_param_as_int("limit")
|
|
|
75 |
result = Mongo.getallSkuDiscountInfo(offset,limit)
|
| 13629 |
kshitij.so |
76 |
json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
|
|
|
77 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13572 |
kshitij.so |
78 |
|
|
|
79 |
|
|
|
80 |
def on_post(self, req, resp):
|
|
|
81 |
|
|
|
82 |
try:
|
|
|
83 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
84 |
except ValueError:
|
|
|
85 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
86 |
'Malformed JSON',
|
|
|
87 |
'Could not decode the request body. The '
|
|
|
88 |
'JSON was incorrect.')
|
|
|
89 |
|
|
|
90 |
result = Mongo.addSkuDiscountInfo(result_json)
|
|
|
91 |
resp.body = json.dumps(result, encoding='utf-8')
|
| 13970 |
kshitij.so |
92 |
|
|
|
93 |
def on_put(self, req, resp, _id):
|
|
|
94 |
try:
|
|
|
95 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
96 |
except ValueError:
|
|
|
97 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
98 |
'Malformed JSON',
|
|
|
99 |
'Could not decode the request body. The '
|
|
|
100 |
'JSON was incorrect.')
|
|
|
101 |
|
|
|
102 |
result = Mongo.updateSkuDiscount(result_json, _id)
|
|
|
103 |
resp.body = json.dumps(result, encoding='utf-8')
|
| 13572 |
kshitij.so |
104 |
|
|
|
105 |
class ExceptionalNlc():
|
|
|
106 |
|
|
|
107 |
def on_get(self, req, resp):
|
| 13629 |
kshitij.so |
108 |
|
| 13970 |
kshitij.so |
109 |
offset = req.get_param_as_int("offset")
|
|
|
110 |
limit = req.get_param_as_int("limit")
|
|
|
111 |
|
|
|
112 |
result = Mongo.getAllExceptionlNlcItems(offset, limit)
|
| 13629 |
kshitij.so |
113 |
json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
|
|
|
114 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13572 |
kshitij.so |
115 |
|
|
|
116 |
def on_post(self, req, resp):
|
|
|
117 |
|
|
|
118 |
try:
|
|
|
119 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
120 |
except ValueError:
|
|
|
121 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
122 |
'Malformed JSON',
|
|
|
123 |
'Could not decode the request body. The '
|
|
|
124 |
'JSON was incorrect.')
|
|
|
125 |
|
|
|
126 |
result = Mongo.addExceptionalNlc(result_json)
|
|
|
127 |
resp.body = json.dumps(result, encoding='utf-8')
|
| 13970 |
kshitij.so |
128 |
|
|
|
129 |
def on_put(self, req, resp, _id):
|
|
|
130 |
try:
|
|
|
131 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
132 |
except ValueError:
|
|
|
133 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
134 |
'Malformed JSON',
|
|
|
135 |
'Could not decode the request body. The '
|
|
|
136 |
'JSON was incorrect.')
|
|
|
137 |
|
|
|
138 |
result = Mongo.updateExceptionalNlc(result_json, _id)
|
|
|
139 |
resp.body = json.dumps(result, encoding='utf-8')
|
| 13572 |
kshitij.so |
140 |
|
| 13772 |
kshitij.so |
141 |
class Deals():
|
| 13779 |
kshitij.so |
142 |
def on_get(self,req, resp, userId):
|
|
|
143 |
categoryId = req.get_param_as_int("categoryId")
|
|
|
144 |
offset = req.get_param_as_int("offset")
|
|
|
145 |
limit = req.get_param_as_int("limit")
|
| 13798 |
kshitij.so |
146 |
sort = req.get_param("sort")
|
| 13802 |
kshitij.so |
147 |
direction = req.get_param_as_int("direction")
|
| 14034 |
kshitij.so |
148 |
result = Mongo.getNewDeals(userId, categoryId, offset, limit, sort, direction)
|
| 13772 |
kshitij.so |
149 |
json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
|
| 13966 |
kshitij.so |
150 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13790 |
kshitij.so |
151 |
|
|
|
152 |
class MasterData():
|
|
|
153 |
def on_get(self,req, resp, skuId):
|
|
|
154 |
result = Mongo.getItem(skuId)
|
| 13798 |
kshitij.so |
155 |
try:
|
|
|
156 |
json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
|
| 13966 |
kshitij.so |
157 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13798 |
kshitij.so |
158 |
except:
|
|
|
159 |
json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
|
| 13966 |
kshitij.so |
160 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13790 |
kshitij.so |
161 |
|
| 13827 |
kshitij.so |
162 |
class LiveData():
|
|
|
163 |
def on_get(self,req, resp):
|
| 13865 |
kshitij.so |
164 |
if req.get_param_as_int("id") is not None:
|
|
|
165 |
print "****getting only for id"
|
|
|
166 |
id = req.get_param_as_int("id")
|
|
|
167 |
try:
|
|
|
168 |
result = FetchLivePrices.getLatestPriceById(id)
|
| 13867 |
kshitij.so |
169 |
json_docs = json.dumps(result, default=json_util.default)
|
| 13966 |
kshitij.so |
170 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13865 |
kshitij.so |
171 |
except:
|
|
|
172 |
json_docs = json.dumps({}, default=json_util.default)
|
| 13966 |
kshitij.so |
173 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13834 |
kshitij.so |
174 |
|
| 13865 |
kshitij.so |
175 |
else:
|
|
|
176 |
print "****getting only for skuId"
|
|
|
177 |
skuBundleId = req.get_param_as_int("skuBundleId")
|
|
|
178 |
source_id = req.get_param_as_int("source_id")
|
|
|
179 |
try:
|
|
|
180 |
result = FetchLivePrices.getLatestPrice(skuBundleId, source_id)
|
|
|
181 |
json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
|
| 13966 |
kshitij.so |
182 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13865 |
kshitij.so |
183 |
except:
|
|
|
184 |
json_docs = [json.dumps(doc, default=json_util.default) for doc in [{}]]
|
| 13966 |
kshitij.so |
185 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13865 |
kshitij.so |
186 |
|
| 13834 |
kshitij.so |
187 |
class CashBack():
|
|
|
188 |
def on_get(self,req, resp):
|
|
|
189 |
identifier = req.get_param("identifier")
|
|
|
190 |
source_id = req.get_param_as_int("source_id")
|
|
|
191 |
try:
|
| 13838 |
kshitij.so |
192 |
result = Mongo.getCashBackDetails(identifier, source_id)
|
| 13837 |
kshitij.so |
193 |
json_docs = json.dumps(result, default=json_util.default)
|
| 13964 |
kshitij.so |
194 |
resp.body = json_docs
|
| 13834 |
kshitij.so |
195 |
except:
|
| 13837 |
kshitij.so |
196 |
json_docs = json.dumps({}, default=json_util.default)
|
| 13963 |
kshitij.so |
197 |
resp.body = json_docs
|
| 13892 |
kshitij.so |
198 |
|
|
|
199 |
class DealSheet():
|
|
|
200 |
def on_get(self,req, resp):
|
| 13895 |
kshitij.so |
201 |
X_DealSheet.sendMail()
|
| 13897 |
kshitij.so |
202 |
json_docs = json.dumps({'True':'Sheet generated, mail sent.'}, default=json_util.default)
|
| 13966 |
kshitij.so |
203 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 13892 |
kshitij.so |
204 |
|
| 13970 |
kshitij.so |
205 |
class DealerPrice():
|
|
|
206 |
|
|
|
207 |
def on_get(self, req, resp):
|
|
|
208 |
|
|
|
209 |
offset = req.get_param_as_int("offset")
|
|
|
210 |
limit = req.get_param_as_int("limit")
|
|
|
211 |
result = Mongo.getAllDealerPrices(offset,limit)
|
|
|
212 |
json_docs = [json.dumps(doc, default=json_util.default) for doc in result]
|
|
|
213 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
|
|
214 |
|
|
|
215 |
def on_post(self, req, resp):
|
|
|
216 |
|
|
|
217 |
try:
|
|
|
218 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
219 |
except ValueError:
|
|
|
220 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
221 |
'Malformed JSON',
|
|
|
222 |
'Could not decode the request body. The '
|
|
|
223 |
'JSON was incorrect.')
|
|
|
224 |
|
|
|
225 |
result = Mongo.addSkuDealerPrice(result_json)
|
|
|
226 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
227 |
|
|
|
228 |
def on_put(self, req, resp, _id):
|
|
|
229 |
try:
|
|
|
230 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
231 |
except ValueError:
|
|
|
232 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
233 |
'Malformed JSON',
|
|
|
234 |
'Could not decode the request body. The '
|
|
|
235 |
'JSON was incorrect.')
|
|
|
236 |
|
|
|
237 |
result = Mongo.updateSkuDealerPrice(result_json, _id)
|
|
|
238 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
239 |
|
|
|
240 |
|
| 14041 |
kshitij.so |
241 |
class ResetCache():
|
|
|
242 |
|
|
|
243 |
def on_get(self,req, resp, userId):
|
| 14044 |
kshitij.so |
244 |
result = Mongo.resetCache(userId)
|
| 14046 |
kshitij.so |
245 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
246 |
|
|
|
247 |
class UserDeals():
|
|
|
248 |
def on_get(self,req,resp,userId):
|
|
|
249 |
UserSpecificDeals.generateSheet(userId)
|
|
|
250 |
json_docs = json.dumps({'True':'Sheet generated, mail sent.'}, default=json_util.default)
|
|
|
251 |
resp.body = json.dumps(json_docs, encoding='utf-8')
|
| 14075 |
kshitij.so |
252 |
|
|
|
253 |
|
|
|
254 |
|
|
|
255 |
class CommonUpdate():
|
|
|
256 |
|
|
|
257 |
def on_post(self,req,resp):
|
|
|
258 |
try:
|
|
|
259 |
result_json = json.loads(req.stream.read(), encoding='utf-8')
|
|
|
260 |
except ValueError:
|
|
|
261 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
262 |
'Malformed JSON',
|
|
|
263 |
'Could not decode the request body. The '
|
|
|
264 |
'JSON was incorrect.')
|
|
|
265 |
|
|
|
266 |
result = Mongo.updateCollection(result_json)
|
|
|
267 |
resp.body = json.dumps(result, encoding='utf-8')
|