| 11110 |
kshitij.so |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
|
|
3 |
import java.io.BufferedReader;
|
|
|
4 |
import java.io.IOException;
|
|
|
5 |
import java.io.InputStreamReader;
|
|
|
6 |
import java.util.List;
|
|
|
7 |
|
|
|
8 |
import javax.servlet.ServletContext;
|
|
|
9 |
import javax.servlet.http.HttpServletRequest;
|
|
|
10 |
import javax.servlet.http.HttpServletResponse;
|
|
|
11 |
import javax.servlet.http.HttpSession;
|
|
|
12 |
|
|
|
13 |
import org.apache.commons.httpclient.HttpClient;
|
|
|
14 |
import org.apache.commons.lang.xwork.StringUtils;
|
|
|
15 |
import org.apache.http.client.ClientProtocolException;
|
|
|
16 |
import org.apache.http.client.methods.HttpGet;
|
|
|
17 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
18 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
19 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
20 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
21 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
|
|
22 |
import org.apache.struts2.util.ServletContextAware;
|
|
|
23 |
import org.apache.thrift.TException;
|
|
|
24 |
import org.json.JSONArray;
|
|
|
25 |
import org.json.JSONException;
|
|
|
26 |
import org.json.JSONObject;
|
|
|
27 |
import org.slf4j.Logger;
|
|
|
28 |
import org.slf4j.LoggerFactory;
|
|
|
29 |
|
|
|
30 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
|
|
31 |
import in.shop2020.model.v1.catalog.FlipkartItem;
|
|
|
32 |
import in.shop2020.model.v1.catalog.MarketplaceHistory;
|
|
|
33 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
34 |
|
|
|
35 |
import com.google.api.client.http.HttpResponse;
|
|
|
36 |
import com.google.gson.Gson;
|
|
|
37 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
|
|
38 |
|
|
|
39 |
@SuppressWarnings({"unused"})
|
|
|
40 |
|
|
|
41 |
@InterceptorRefs({
|
|
|
42 |
@InterceptorRef("defaultStack"),
|
|
|
43 |
@InterceptorRef("login")
|
|
|
44 |
})
|
|
|
45 |
|
|
|
46 |
public class SnapdealScraperController extends ValidationAwareSupport implements ServletRequestAware ,ServletResponseAware, ServletContextAware{
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
*
|
|
|
50 |
*/
|
|
|
51 |
private static final long serialVersionUID = 105919058664635958L;
|
|
|
52 |
|
|
|
53 |
private static Logger logger = LoggerFactory.getLogger(SnapdealScraperController.class);
|
|
|
54 |
|
|
|
55 |
private HttpServletRequest request;
|
|
|
56 |
private HttpServletResponse response;
|
|
|
57 |
private HttpSession session;
|
|
|
58 |
private ServletContext context;
|
|
|
59 |
private String supc;
|
|
|
60 |
private JSONObject scrapingObj;
|
|
|
61 |
// private String saholicSp;
|
|
|
62 |
// private String saholicOfferPrice;
|
|
|
63 |
// private String saholicTp;
|
|
|
64 |
// private String saholicRank;
|
|
|
65 |
// private String competitor;
|
|
|
66 |
// private String competitorSp;
|
|
|
67 |
// private String competitorOfferPrice;
|
|
|
68 |
// private String competitorTp;
|
|
|
69 |
// private String competitorInventory;
|
|
|
70 |
// private String ourInventory;
|
|
|
71 |
// private String subsidyDiff;
|
|
|
72 |
|
|
|
73 |
public String index() throws ClientProtocolException, IOException, JSONException{
|
|
|
74 |
DefaultHttpClient client = new DefaultHttpClient();
|
| 12824 |
kshitij.so |
75 |
HttpGet request = new HttpGet("http://www.snapdeal.com/acors/json/gvbps?supc="+supc+"&catId=175"+"&sort=sellingPrice");
|
| 11110 |
kshitij.so |
76 |
org.apache.http.HttpResponse response = client.execute(request);
|
|
|
77 |
|
|
|
78 |
// Get the response
|
|
|
79 |
BufferedReader rd = new BufferedReader
|
|
|
80 |
(new InputStreamReader(response.getEntity().getContent()));
|
|
|
81 |
|
|
|
82 |
String line = "";
|
|
|
83 |
StringBuilder sb = new StringBuilder();
|
|
|
84 |
double ourOfferPrice = 0 , ourSp = 0 , secondLowestSellerSp= 0,lowestOfferPrice= 0 , secondLowestSellerOfferPrice=0, lowestSp=0;
|
|
|
85 |
int otherInventory = 0 ,ourInventory = 0, rank=0, secondLowestSellerInventory=0;
|
|
|
86 |
String lowestSellerName ="", lowestSellerCode="", secondLowestSellerName="", secondLowestSellerCode="";
|
|
|
87 |
while ((line = rd.readLine()) != null) {
|
|
|
88 |
sb.append(line);
|
|
|
89 |
}
|
|
|
90 |
JSONArray jsonArray = new JSONArray(sb.toString());
|
|
|
91 |
int totalSeller = jsonArray.length();
|
|
|
92 |
for (int i = 0, size = jsonArray.length(); i < size; i++){
|
|
|
93 |
JSONObject x = jsonArray.getJSONObject(i);
|
|
|
94 |
if (i==0){
|
|
|
95 |
lowestSellerName = x.getString("vendorDisplayName");
|
|
|
96 |
lowestSellerCode = x.getString("vendorCode");
|
|
|
97 |
try{
|
|
|
98 |
lowestSp = Double.valueOf(x.getString("sellingPriceBefIntCashBack"));
|
|
|
99 |
}
|
|
|
100 |
catch(Exception e){
|
|
|
101 |
lowestSp = Double.valueOf(x.getString("sellingPrice"));
|
|
|
102 |
}
|
|
|
103 |
lowestOfferPrice = Double.valueOf(x.getString("sellingPrice"));
|
|
|
104 |
}
|
|
|
105 |
if (i==1){
|
|
|
106 |
secondLowestSellerName = x.getString("vendorDisplayName");
|
|
|
107 |
secondLowestSellerCode = x.getString("vendorCode");
|
|
|
108 |
try{
|
|
|
109 |
secondLowestSellerSp = Double.valueOf(x.getString("sellingPriceBefIntCashBack"));
|
|
|
110 |
}
|
|
|
111 |
catch(Exception e){
|
|
|
112 |
secondLowestSellerSp = Double.valueOf(x.getString("sellingPrice"));
|
|
|
113 |
}
|
|
|
114 |
secondLowestSellerOfferPrice = Double.valueOf(x.getString("sellingPrice"));
|
|
|
115 |
secondLowestSellerInventory = Integer.valueOf(x.getString("buyableInventory"));
|
|
|
116 |
}
|
|
|
117 |
if(StringUtils.equals("MobilesnMore", x.getString("vendorDisplayName"))){
|
|
|
118 |
ourInventory = Integer.valueOf(x.getString("buyableInventory"));
|
|
|
119 |
try{
|
|
|
120 |
ourSp = Double.valueOf(x.getString("sellingPriceBefIntCashBack"));
|
|
|
121 |
}
|
|
|
122 |
catch(Exception e){
|
|
|
123 |
ourSp = Double.valueOf(x.getString("sellingPrice"));
|
|
|
124 |
}
|
|
|
125 |
ourOfferPrice = Double.valueOf(x.getString("sellingPrice"));
|
|
|
126 |
rank = i +1;
|
|
|
127 |
}
|
|
|
128 |
else{
|
|
|
129 |
if (rank==0){
|
|
|
130 |
otherInventory = otherInventory +Integer.valueOf(x.getString("buyableInventory"));
|
|
|
131 |
}
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
scrapingObj = new JSONObject();
|
|
|
135 |
scrapingObj.put("saholicSp",ourSp);
|
|
|
136 |
scrapingObj.put("saholicOfferPrice",ourOfferPrice);
|
|
|
137 |
scrapingObj.put("saholicInventory",ourInventory);
|
|
|
138 |
scrapingObj.put("saholicRank",rank);
|
|
|
139 |
if(rank==1 && totalSeller>1){
|
|
|
140 |
scrapingObj.put("competitorSp",secondLowestSellerSp);
|
|
|
141 |
scrapingObj.put("competitorOfferPrice",secondLowestSellerOfferPrice);
|
|
|
142 |
scrapingObj.put("competitorInventory",secondLowestSellerInventory);
|
| 11122 |
kshitij.so |
143 |
scrapingObj.put("competitorName",secondLowestSellerName);
|
|
|
144 |
scrapingObj.put("competitorType","Second Lowest Seller");
|
| 11110 |
kshitij.so |
145 |
}
|
|
|
146 |
else if (rank==1 && totalSeller==1){
|
|
|
147 |
scrapingObj.put("competitorSp","");
|
|
|
148 |
scrapingObj.put("competitorOfferPrice","");
|
|
|
149 |
scrapingObj.put("competitorInventory","");
|
| 11122 |
kshitij.so |
150 |
scrapingObj.put("competitorName","");
|
|
|
151 |
scrapingObj.put("competitorType","");
|
| 11110 |
kshitij.so |
152 |
}
|
|
|
153 |
else if (rank!=1 && totalSeller>0){
|
|
|
154 |
scrapingObj.put("competitorSp",lowestSp);
|
|
|
155 |
scrapingObj.put("competitorOfferPrice",lowestOfferPrice);
|
|
|
156 |
scrapingObj.put("competitorInventory",otherInventory);
|
| 11122 |
kshitij.so |
157 |
scrapingObj.put("competitorName",lowestSellerName);
|
|
|
158 |
scrapingObj.put("competitorType","Lowest Seller");
|
|
|
159 |
|
| 11110 |
kshitij.so |
160 |
}
|
|
|
161 |
scrapingObj.put("totalSeller", totalSeller);
|
|
|
162 |
}
|
|
|
163 |
return "item-details-json";
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
public void setSupc(String supc) {
|
|
|
168 |
this.supc = supc;
|
|
|
169 |
}
|
|
|
170 |
//
|
|
|
171 |
//
|
|
|
172 |
// public String getSaholicSp() {
|
|
|
173 |
// return saholicSp;
|
|
|
174 |
// }
|
|
|
175 |
//
|
|
|
176 |
//
|
|
|
177 |
// public void setSaholicOfferPrice(String saholicOfferPrice) {
|
|
|
178 |
// this.saholicOfferPrice = saholicOfferPrice;
|
|
|
179 |
// }
|
|
|
180 |
//
|
|
|
181 |
//
|
|
|
182 |
// public String getSaholicOfferPrice() {
|
|
|
183 |
// return saholicOfferPrice;
|
|
|
184 |
// }
|
|
|
185 |
//
|
|
|
186 |
//
|
|
|
187 |
// public void setSaholicRank(String saholicRank) {
|
|
|
188 |
// this.saholicRank = saholicRank;
|
|
|
189 |
// }
|
|
|
190 |
//
|
|
|
191 |
//
|
|
|
192 |
// public String getSaholicRank() {
|
|
|
193 |
// return saholicRank;
|
|
|
194 |
// }
|
|
|
195 |
//
|
|
|
196 |
//
|
|
|
197 |
// public void setSaholicTp(String saholicTp) {
|
|
|
198 |
// this.saholicTp = saholicTp;
|
|
|
199 |
// }
|
|
|
200 |
//
|
|
|
201 |
//
|
|
|
202 |
// public String getSaholicTp() {
|
|
|
203 |
// return saholicTp;
|
|
|
204 |
// }
|
|
|
205 |
//
|
|
|
206 |
//
|
|
|
207 |
// public void setCompetitorSp(String competitorSp) {
|
|
|
208 |
// this.competitorSp = competitorSp;
|
|
|
209 |
// }
|
|
|
210 |
//
|
|
|
211 |
//
|
|
|
212 |
// public String getCompetitorSp() {
|
|
|
213 |
// return competitorSp;
|
|
|
214 |
// }
|
|
|
215 |
//
|
|
|
216 |
//
|
|
|
217 |
// public void setCompetitor(String competitor) {
|
|
|
218 |
// this.competitor = competitor;
|
|
|
219 |
// }
|
|
|
220 |
//
|
|
|
221 |
//
|
|
|
222 |
// public String getCompetitor() {
|
|
|
223 |
// return competitor;
|
|
|
224 |
// }
|
|
|
225 |
|
|
|
226 |
|
|
|
227 |
public String getItemDetails(){
|
|
|
228 |
return scrapingObj.toString();
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
|
|
|
232 |
@Override
|
|
|
233 |
public void setServletContext(ServletContext arg0) {
|
|
|
234 |
// TODO Auto-generated method stub
|
|
|
235 |
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
public HttpServletRequest getRequest() {
|
|
|
239 |
logger.info("set request"+request.toString());
|
|
|
240 |
return request;
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
public void setRequest(HttpServletRequest request) {
|
|
|
244 |
this.request = request;
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
public HttpServletResponse getResponse() {
|
|
|
248 |
return response;
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
public void setResponse(HttpServletResponse response) {
|
|
|
252 |
this.response = response;
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
public HttpSession getSession() {
|
|
|
256 |
return session;
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
public void setSession(HttpSession session) {
|
|
|
260 |
this.session = session;
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
public ServletContext getContext() {
|
|
|
264 |
return context;
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
public void setContext(ServletContext context) {
|
|
|
268 |
this.context = context;
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
|
|
|
272 |
@Override
|
|
|
273 |
public void setServletResponse(HttpServletResponse arg0) {
|
|
|
274 |
// TODO Auto-generated method stub
|
|
|
275 |
|
|
|
276 |
}
|
|
|
277 |
|
|
|
278 |
|
|
|
279 |
@Override
|
|
|
280 |
public void setServletRequest(HttpServletRequest arg0) {
|
|
|
281 |
// TODO Auto-generated method stub
|
|
|
282 |
|
|
|
283 |
}
|
|
|
284 |
|
|
|
285 |
|
|
|
286 |
// public void setCompetitorOfferPrice(String competitorOfferPrice) {
|
|
|
287 |
// this.competitorOfferPrice = competitorOfferPrice;
|
|
|
288 |
// }
|
|
|
289 |
//
|
|
|
290 |
//
|
|
|
291 |
// public String getCompetitorOfferPrice() {
|
|
|
292 |
// return competitorOfferPrice;
|
|
|
293 |
// }
|
|
|
294 |
//
|
|
|
295 |
//
|
|
|
296 |
// public void setCompetitorTp(String competitorTp) {
|
|
|
297 |
// this.competitorTp = competitorTp;
|
|
|
298 |
// }
|
|
|
299 |
//
|
|
|
300 |
//
|
|
|
301 |
// public String getCompetitorTp() {
|
|
|
302 |
// return competitorTp;
|
|
|
303 |
// }
|
|
|
304 |
//
|
|
|
305 |
//
|
|
|
306 |
// public void setCompetitorInventory(String competitorInventory) {
|
|
|
307 |
// this.competitorInventory = competitorInventory;
|
|
|
308 |
// }
|
|
|
309 |
//
|
|
|
310 |
//
|
|
|
311 |
// public String getCompetitorInventory() {
|
|
|
312 |
// return competitorInventory;
|
|
|
313 |
// }
|
|
|
314 |
//
|
|
|
315 |
//
|
|
|
316 |
// public void setOurInventory(String ourInventory) {
|
|
|
317 |
// this.ourInventory = ourInventory;
|
|
|
318 |
// }
|
|
|
319 |
//
|
|
|
320 |
//
|
|
|
321 |
// public String getOurInventory() {
|
|
|
322 |
// return ourInventory;
|
|
|
323 |
// }
|
|
|
324 |
//
|
|
|
325 |
//
|
|
|
326 |
// public void setSubsidyDiff(String subsidyDiff) {
|
|
|
327 |
// this.subsidyDiff = subsidyDiff;
|
|
|
328 |
// }
|
|
|
329 |
//
|
|
|
330 |
//
|
|
|
331 |
// public String getSubsidyDiff() {
|
|
|
332 |
// return subsidyDiff;
|
|
|
333 |
// }
|
|
|
334 |
}
|