| Line 1... |
Line 1... |
| 1 |
package in.shop2020;
|
1 |
package in.shop2020;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.model.v1.catalog.MarketPlaceItemPrice;
|
3 |
import in.shop2020.model.v1.catalog.MarketPlaceItemPrice;
|
| 4 |
import in.shop2020.model.v1.catalog.SnapdealItemDetails;
|
4 |
import in.shop2020.model.v1.catalog.SnapdealItemDetails;
|
| - |
|
5 |
import in.shop2020.serving.services.SnapdealSessionCookie;
|
| 5 |
import in.shop2020.thrift.clients.CatalogClient;
|
6 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 6 |
import in.shop2020.utils.GmailUtils;
|
7 |
import in.shop2020.utils.GmailUtils;
|
| 7 |
import inventory.Inventory;
|
8 |
import inventory.Inventory;
|
| 8 |
import inventory.InventoryHistoryItems;
|
9 |
import inventory.InventoryHistoryItems;
|
| 9 |
|
10 |
|
| Line 39... |
Line 40... |
| 39 |
import org.apache.poi.ss.usermodel.Row;
|
40 |
import org.apache.poi.ss.usermodel.Row;
|
| 40 |
import org.apache.poi.ss.usermodel.Sheet;
|
41 |
import org.apache.poi.ss.usermodel.Sheet;
|
| 41 |
import org.apache.poi.ss.usermodel.Workbook;
|
42 |
import org.apache.poi.ss.usermodel.Workbook;
|
| 42 |
import org.apache.thrift.TException;
|
43 |
import org.apache.thrift.TException;
|
| 43 |
import org.apache.thrift.transport.TTransportException;
|
44 |
import org.apache.thrift.transport.TTransportException;
|
| - |
|
45 |
import org.json.JSONObject;
|
| 44 |
|
46 |
|
| 45 |
import pricing.CurrentPricing;
|
47 |
import pricing.CurrentPricing;
|
| 46 |
import pricing.CurrentPricingItems;
|
48 |
import pricing.CurrentPricingItems;
|
| 47 |
import pricing.PricingHistory;
|
49 |
import pricing.PricingHistory;
|
| 48 |
import pricing.PricingHistoryItems;
|
50 |
import pricing.PricingHistoryItems;
|
| Line 63... |
Line 65... |
| 63 |
private static SimpleDateFormat sdf;
|
65 |
private static SimpleDateFormat sdf;
|
| 64 |
private static String emailFromAddress;
|
66 |
private static String emailFromAddress;
|
| 65 |
private static String password;
|
67 |
private static String password;
|
| 66 |
private static GmailUtils mailer;
|
68 |
private static GmailUtils mailer;
|
| 67 |
private static String[] sendTo;
|
69 |
private static String[] sendTo;
|
| - |
|
70 |
private static Map<String, String> headers = new HashMap<String, String>();
|
| 68 |
|
71 |
|
| 69 |
static {
|
72 |
static {
|
| 70 |
sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
|
73 |
sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
|
| 71 |
emailFromAddress = "build@shop2020.in";
|
74 |
emailFromAddress = "build@shop2020.in";
|
| 72 |
password = "cafe@nes";
|
75 |
password = "cafe@nes";
|
| Line 102... |
Line 105... |
| 102 |
}
|
105 |
}
|
| 103 |
for(SnapdealItemDetails snapdealItem:allSnapdealItems){
|
106 |
for(SnapdealItemDetails snapdealItem:allSnapdealItems){
|
| 104 |
snapdealItemMap.put(snapdealItem.getSkuAtSnapdeal(),snapdealItem);
|
107 |
snapdealItemMap.put(snapdealItem.getSkuAtSnapdeal(),snapdealItem);
|
| 105 |
itemSnapdealMap.put(snapdealItem.getItem_id(), snapdealItem);
|
108 |
itemSnapdealMap.put(snapdealItem.getItem_id(), snapdealItem);
|
| 106 |
}
|
109 |
}
|
| - |
|
110 |
|
| - |
|
111 |
headers.put("User-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11");
|
| - |
|
112 |
headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
| - |
|
113 |
headers.put("Accept-Language", "en-US,en;q=0.8");
|
| - |
|
114 |
headers.put("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
|
| 107 |
|
115 |
|
| 108 |
}
|
116 |
}
|
| 109 |
public static void handleLogin() throws ClientProtocolException, IOException{
|
- |
|
| 110 |
HttpGet get = new HttpGet("http://selleraccounts.snapdeal.com/login?service=http%3A%2F%2Fseller.snapdeal.com%2Fj_spring_cas_security_check");
|
- |
|
| 111 |
HttpResponse response = null;
|
- |
|
| 112 |
try {
|
- |
|
| 113 |
response = client.execute(get);
|
- |
|
| 114 |
} catch (ClientProtocolException e) {
|
- |
|
| 115 |
// TODO Auto-generated catch block
|
- |
|
| 116 |
e.printStackTrace();
|
- |
|
| 117 |
} catch (IOException e) {
|
- |
|
| 118 |
// TODO Auto-generated catch block
|
- |
|
| 119 |
e.printStackTrace();
|
- |
|
| 120 |
}
|
- |
|
| 121 |
BufferedReader rd = null;
|
- |
|
| 122 |
try {
|
- |
|
| 123 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
- |
|
| 124 |
} catch (IllegalStateException e1) {
|
- |
|
| 125 |
// TODO Auto-generated catch block
|
- |
|
| 126 |
e1.printStackTrace();
|
- |
|
| 127 |
} catch (IOException e1) {
|
- |
|
| 128 |
// TODO Auto-generated catch block
|
- |
|
| 129 |
e1.printStackTrace();
|
- |
|
| 130 |
}
|
- |
|
| 131 |
String line = "";
|
- |
|
| 132 |
StringBuffer sb = new StringBuffer();
|
- |
|
| 133 |
try {
|
- |
|
| 134 |
while ((line = rd.readLine()) != null) {
|
- |
|
| 135 |
sb.append(line);
|
- |
|
| 136 |
System.out.println(line);
|
- |
|
| 137 |
}
|
- |
|
| 138 |
} catch (IOException e) {
|
- |
|
| 139 |
// TODO Auto-generated catch block
|
- |
|
| 140 |
e.printStackTrace();
|
- |
|
| 141 |
}
|
- |
|
| 142 |
int i= sb.toString().indexOf("name=\"lt\" value=");
|
- |
|
| 143 |
char[] charArray = sb.toString().toCharArray();
|
- |
|
| 144 |
String lt = "";
|
- |
|
| 145 |
int j=0;
|
- |
|
| 146 |
for(j=i+16;j<=charArray.length;j++){
|
- |
|
| 147 |
|
- |
|
| 148 |
if(charArray[j]==' '){
|
- |
|
| 149 |
break;
|
- |
|
| 150 |
}
|
- |
|
| 151 |
}
|
- |
|
| 152 |
lt = sb.substring(i+17,j-1);
|
- |
|
| 153 |
System.out.println("LT VALUE " + lt);
|
- |
|
| 154 |
i= sb.toString().indexOf("name=\"execution\" value=");
|
- |
|
| 155 |
charArray = sb.toString().toCharArray();
|
- |
|
| 156 |
String ex = "";
|
- |
|
| 157 |
j=0;
|
- |
|
| 158 |
for(j=i+24;j<=charArray.length;j++){
|
- |
|
| 159 |
if(charArray[j]==' '){
|
- |
|
| 160 |
break;
|
- |
|
| 161 |
}
|
- |
|
| 162 |
}
|
- |
|
| 163 |
ex = sb.substring(i+24,j-1);
|
- |
|
| 164 |
System.out.println("EXECUTION VALUE " + ex);
|
- |
|
| 165 |
HttpPost post = new HttpPost("http://selleraccounts.snapdeal.com/login?service=http%3A%2F%2Fseller.snapdeal.com%2Fj_spring_cas_security_check");
|
- |
|
| 166 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
- |
|
| 167 |
//nameValuePairs.add(new BasicNameValuePair("username",
|
- |
|
| 168 |
//"khushal.bhatia@saholic.com"));
|
- |
|
| 169 |
nameValuePairs.add(new BasicNameValuePair("username",
|
- |
|
| 170 |
"saholic-snapdeal@saholic.com"));
|
- |
|
| 171 |
//nameValuePairs.add(new BasicNameValuePair("password",
|
- |
|
| 172 |
//"sonline"));
|
- |
|
| 173 |
nameValuePairs.add(new BasicNameValuePair("password",
|
- |
|
| 174 |
"saholic15"));
|
- |
|
| 175 |
nameValuePairs.add(new BasicNameValuePair("_eventId","submit"));
|
- |
|
| 176 |
nameValuePairs.add(new BasicNameValuePair("execution",ex));
|
- |
|
| 177 |
nameValuePairs.add(new BasicNameValuePair("lt",lt));
|
- |
|
| 178 |
nameValuePairs.add(new BasicNameValuePair("submit","LOGIN"));
|
- |
|
| 179 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
- |
|
| 180 |
response = client.execute(post);
|
- |
|
| 181 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
- |
|
| 182 |
line = "";
|
- |
|
| 183 |
while ((line = rd.readLine()) != null) {
|
- |
|
| 184 |
//System.out.println(line);
|
- |
|
| 185 |
}
|
- |
|
| 186 |
get = new HttpGet("http://seller.snapdeal.com/pricing/");
|
- |
|
| 187 |
response = client.execute(get);
|
- |
|
| 188 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
- |
|
| 189 |
while ((line = rd.readLine()) != null) {
|
- |
|
| 190 |
//System.out.println(line);
|
- |
|
| 191 |
}
|
- |
|
| 192 |
}
|
- |
|
| 193 |
|
- |
|
| 194 |
|
117 |
|
| 195 |
public static void main(String... args) throws IOException, InterruptedException{
|
118 |
public static void main(String... args) throws Exception{
|
| 196 |
handleLogin();
|
- |
|
| 197 |
HttpGet get;
|
119 |
HttpGet get;
|
| 198 |
BufferedReader rd= null;
|
120 |
BufferedReader rd= null;
|
| 199 |
Gson gson = new Gson();
|
121 |
Gson gson = new Gson();
|
| 200 |
int i = 1;
|
122 |
int i = 1;
|
| 201 |
boolean exitfetchingcurrent = true;
|
123 |
boolean exitfetchingcurrent = true;
|
| 202 |
System.out.println("Fetching current prices");
|
124 |
System.out.println("Fetching current prices");
|
| 203 |
HttpResponse response;
|
125 |
HttpResponse response;
|
| - |
|
126 |
SnapdealSessionCookie sdSessionCookie = new SnapdealSessionCookie();
|
| - |
|
127 |
String cookies = "";
|
| - |
|
128 |
JSONObject cookieObject = null;
|
| 204 |
while(exitfetchingcurrent){
|
129 |
while(exitfetchingcurrent){
|
| 205 |
get = new HttpGet("http://seller.snapdeal.com/pricing/search?gridType=normal&_search=false&nd="+time+"&rows=30&page="+i+"&sidx=&sord=asc");
|
130 |
get = new HttpGet("http://seller.snapdeal.com/pricing/search?gridType=normal&_search=false&nd="+time+"&rows=30&page="+i+"&sidx=&sord=asc");
|
| - |
|
131 |
cookies = sdSessionCookie.getCookies();
|
| - |
|
132 |
cookieObject = new JSONObject(cookies);
|
| - |
|
133 |
for(String key:headers.keySet())
|
| - |
|
134 |
get.addHeader(key, headers.get(key));
|
| - |
|
135 |
get.addHeader("Cookie","SERVERID="+cookieObject.get("SERVERID")+";sfJSESSIONID="+cookieObject.get("sfJSESSIONID")+";");
|
| 206 |
response = client.execute(get);
|
136 |
response = client.execute(get);
|
| 207 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
137 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 208 |
currentPricingItems = (CurrentPricingItems) gson.fromJson(rd, CurrentPricingItems.class);
|
138 |
currentPricingItems = (CurrentPricingItems) gson.fromJson(rd, CurrentPricingItems.class);
|
| 209 |
if(currentPricingItems.getRows().size()!=0){
|
139 |
if(currentPricingItems.getRows().size()!=0){
|
| 210 |
for(CurrentPricing currentPricing:currentPricingItems.getRows()){
|
140 |
for(CurrentPricing currentPricing:currentPricingItems.getRows()){
|
| Line 252... |
Line 182... |
| 252 |
hwb.write(fileOut);
|
182 |
hwb.write(fileOut);
|
| 253 |
} catch (IOException e) {
|
183 |
} catch (IOException e) {
|
| 254 |
e.printStackTrace();
|
184 |
e.printStackTrace();
|
| 255 |
}
|
185 |
}
|
| 256 |
HttpPost post = new HttpPost("http://seller.snapdeal.com/pricing/upload?uploadType=SP");
|
186 |
HttpPost post = new HttpPost("http://seller.snapdeal.com/pricing/upload?uploadType=SP");
|
| - |
|
187 |
cookies = sdSessionCookie.getCookies();
|
| - |
|
188 |
cookieObject = new JSONObject(cookies);
|
| - |
|
189 |
for(String key:headers.keySet())
|
| - |
|
190 |
post.addHeader(key, headers.get(key));
|
| - |
|
191 |
post.addHeader("Cookie","SERVERID="+cookieObject.get("SERVERID")+";sfJSESSIONID="+cookieObject.get("sfJSESSIONID")+";");
|
| 257 |
File file = new File(SNAPDEAL_PRICING_SHEET);
|
192 |
File file = new File(SNAPDEAL_PRICING_SHEET);
|
| 258 |
MultipartEntity mpEntity = new MultipartEntity();
|
193 |
MultipartEntity mpEntity = new MultipartEntity();
|
| 259 |
ContentBody cbFile = new FileBody(file,"application/vnd.ms-excel");
|
194 |
ContentBody cbFile = new FileBody(file,"application/vnd.ms-excel");
|
| 260 |
mpEntity.addPart("file", cbFile);
|
195 |
mpEntity.addPart("file", cbFile);
|
| 261 |
post.setEntity(mpEntity);
|
196 |
post.setEntity(mpEntity);
|
| Line 299... |
Line 234... |
| 299 |
exitfetchinghistory = true;
|
234 |
exitfetchinghistory = true;
|
| 300 |
System.out.println("Fetching history prices " + j);
|
235 |
System.out.println("Fetching history prices " + j);
|
| 301 |
successfullyUpdated =0;
|
236 |
successfullyUpdated =0;
|
| 302 |
while(exitfetchinghistory){
|
237 |
while(exitfetchinghistory){
|
| 303 |
get = new HttpGet("http://seller.snapdeal.com/pricing/search?gridType=history&_search=false&nd="+time+"&rows=30&page="+i+"&sidx=&sord=asc");
|
238 |
get = new HttpGet("http://seller.snapdeal.com/pricing/search?gridType=history&_search=false&nd="+time+"&rows=30&page="+i+"&sidx=&sord=asc");
|
| - |
|
239 |
cookies = sdSessionCookie.getCookies();
|
| - |
|
240 |
cookieObject = new JSONObject(cookies);
|
| - |
|
241 |
for(String key:headers.keySet())
|
| - |
|
242 |
get.addHeader(key, headers.get(key));
|
| - |
|
243 |
get.addHeader("Cookie","SERVERID="+cookieObject.get("SERVERID")+";sfJSESSIONID="+cookieObject.get("sfJSESSIONID")+";");
|
| 304 |
response = client.execute(get);
|
244 |
response = client.execute(get);
|
| 305 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
245 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 306 |
pricingHistoryItems = (PricingHistoryItems) gson.fromJson(rd, PricingHistoryItems.class);
|
246 |
pricingHistoryItems = (PricingHistoryItems) gson.fromJson(rd, PricingHistoryItems.class);
|
| 307 |
if(pricingHistoryItems.getRows().size()!=0 && successfullyUpdated != (iterator - 1)){
|
247 |
if(pricingHistoryItems.getRows().size()!=0 && successfullyUpdated != (iterator - 1)){
|
| 308 |
for(PricingHistory pricingHistory:pricingHistoryItems.getRows()){
|
248 |
for(PricingHistory pricingHistory:pricingHistoryItems.getRows()){
|