| 12826 |
kshitij.so |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.config.ConfigException;
|
|
|
4 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
|
|
5 |
|
|
|
6 |
import java.io.BufferedReader;
|
|
|
7 |
import java.io.IOException;
|
|
|
8 |
import java.io.InputStreamReader;
|
|
|
9 |
import java.io.UnsupportedEncodingException;
|
|
|
10 |
import java.util.ArrayList;
|
|
|
11 |
import java.util.List;
|
|
|
12 |
|
|
|
13 |
import org.apache.http.HttpResponse;
|
|
|
14 |
import org.apache.http.NameValuePair;
|
|
|
15 |
import org.apache.http.client.ClientProtocolException;
|
|
|
16 |
import org.apache.http.client.HttpClient;
|
|
|
17 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
18 |
import org.apache.http.client.methods.HttpGet;
|
|
|
19 |
import org.apache.http.client.methods.HttpPost;
|
|
|
20 |
import org.apache.http.entity.StringEntity;
|
|
|
21 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
22 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
23 |
import org.json.JSONArray;
|
|
|
24 |
import org.json.JSONException;
|
|
|
25 |
import org.json.JSONObject;
|
|
|
26 |
import org.slf4j.Logger;
|
|
|
27 |
import org.slf4j.LoggerFactory;
|
|
|
28 |
|
|
|
29 |
public class FlipkartPricingPannel{
|
|
|
30 |
|
|
|
31 |
private static Logger logger = LoggerFactory.getLogger(FlipkartPricingPannel.class);
|
|
|
32 |
|
|
|
33 |
public static final String AUTH_NAME = "flipkart";
|
|
|
34 |
public static final String USER_NAME = "flipkart-support@saholic.com";
|
|
|
35 |
public static final String PASSWORD = "076c27ee24d7596b06608a8ed2559f87";
|
|
|
36 |
public static final String SELLER_ID = "m2z93iskuj81qiid";
|
|
|
37 |
public static final String CSRF = "wuru84MMNRMhRCWtlhydVdN9";
|
|
|
38 |
public static final String COOKIE = "T=TI141147280750274359991498309202525657388536723248248488328249492067; " +
|
|
|
39 |
"__sonar=16983180403917152637; __gads=ID=c15eba68f7f44861:T=1411472817:S=ALNI_MYyU0QfJ923BqkcDhqFlRpZxMcA8w; " +
|
|
|
40 |
"cmp_id=hp_dotd_4_DOTDOnBajajMixerGrinder_Sep23.|1414064820638; S=d1t16GpsIdt0JTsYuFF%2FMaE7jTGYozxMXM5a3ktJD24TBohceobkUv8l4GDr4KNLkLs5BOgnhsqkZNQRh2Lzrx%2B77zQ%3D%3D; " +
|
|
|
41 |
"km_lv=x; __utma=19769839.1065606807.1411472808.1411472808.1411624009.2; __utmc=19769839; __utmz=19769839.1411472808.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);" +
|
|
|
42 |
" s_cc=true; s_sq=%5B%5BB%5D%5D; prd_day=2|1411645620637; s_ppv=21; SN=2.VI89D3B4F7B5534B3C9EADE3BBD925875A.SI05ED43E07EAF40E9B4F265F5F2B1074D.VS141162400679268773093.1411624676;" +
|
|
|
43 |
"VID=2.VI89D3B4F7B5534B3C9EADE3BBD925875A.1411624676.VS141162400679268773093; NSID=2.SI05ED43E07EAF40E9B4F265F5F2B1074D.1411624676.VI89D3B4F7B5534B3C9EADE3BBD925875A; " +
|
|
|
44 |
"connect.sid=s%3AaUlfUN00goYPkqRHXtAbM6Nh.EBDDk9%2F0rQDXGb%2B23IEJ4QgrAgKFpXU%2FLOjuQyxJo44; is_login=true; sellerId=m2z93iskuj81qiid; __utma=143439159.1617147053.1411568832.1411568832.1411624688.2; " +
|
|
|
45 |
"__utmb=143439159.17.10.1411624688; __utmc=143439159; __utmz=143439159.1411568832.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _ga=GA1.2.1617147053.1411568832; _gat=1; kvcd=1411627978463; km_ai=m2z93iskuj81qiid; " +
|
|
|
46 |
"km_ni=m2z93iskuj81qiid; km_vs=1; km_uq=";
|
|
|
47 |
|
|
|
48 |
public static final String SELLER_HOME = "seller.flipkart.com";
|
|
|
49 |
public static final String USER_AGENT = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63";
|
|
|
50 |
public static final HttpClient client = new DefaultHttpClient();
|
|
|
51 |
|
|
|
52 |
private static String UPDATE_PRICE_ON_FK;
|
|
|
53 |
|
|
|
54 |
static{
|
|
|
55 |
try {
|
|
|
56 |
UPDATE_PRICE_ON_FK = ConfigClient.getClient().get("sync_price_on_marketplace");
|
|
|
57 |
} catch (ConfigException e) {
|
|
|
58 |
logger.error("Unable to get sync prices on marketplace", e);
|
|
|
59 |
UPDATE_PRICE_ON_FK = "false";
|
|
|
60 |
}
|
| 12828 |
kshitij.so |
61 |
logger.info(UPDATE_PRICE_ON_FK);
|
| 12826 |
kshitij.so |
62 |
}
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
public boolean updatePrice(String skuAtFlipkart, String sellingPrice) throws ClientProtocolException, IOException, JSONException{
|
|
|
66 |
|
| 12834 |
kshitij.so |
67 |
if (Boolean.valueOf(UPDATE_PRICE_ON_FK)){
|
| 12826 |
kshitij.so |
68 |
return true;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
HttpPost post = new HttpPost("https://seller.flipkart.com/login");
|
|
|
72 |
BufferedReader rd= null;
|
|
|
73 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
74 |
nameValuePairs.add(new BasicNameValuePair("authName",
|
|
|
75 |
AUTH_NAME));
|
|
|
76 |
nameValuePairs.add(new BasicNameValuePair("username",
|
|
|
77 |
USER_NAME));
|
|
|
78 |
nameValuePairs.add(new BasicNameValuePair("password",
|
|
|
79 |
PASSWORD));
|
|
|
80 |
post.addHeader("Cookie",COOKIE);
|
|
|
81 |
post.addHeader("User-agent", USER_AGENT);
|
|
|
82 |
post.addHeader("Referer", SELLER_HOME);
|
|
|
83 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
|
|
84 |
HttpResponse response = client.execute(post);
|
|
|
85 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
86 |
String line="";
|
|
|
87 |
while ((line = rd.readLine()) != null) {
|
|
|
88 |
System.out.println(line);
|
|
|
89 |
}
|
|
|
90 |
String data = "{\"refiners\":{\"sku_id\":[\""+skuAtFlipkart+"\"]},\"verticalGroup\":{},\"sellerId\":\""+SELLER_ID+"\",\"pageSize\":10,\"pageNumber\":1,\"state\":\"LIVE\"}";
|
|
|
91 |
//String data = "{\"refiners\":{\"sku_id\":[\"12442\"]},\"verticalGroup\":{},\"sellerId\":\"m2z93iskuj81qiid\",\"pageSize\":10,\"pageNumb
|
| 12828 |
kshitij.so |
92 |
logger.info(data);
|
| 12826 |
kshitij.so |
93 |
//HttpGet get_new = new HttpGet("https://seller.flipkart.com/dashboard/som/new_order_items?status=on_hold%2Capproved.payment_approved&sort=confirm_by_date&page="+i+"&page_size=100&_="+time);
|
|
|
94 |
HttpPost httppost = new HttpPost("https://seller.flipkart.com/sellerListing/listing/listingsForContext?sellerId=m2z93iskuj81qiid");
|
|
|
95 |
httppost.addHeader("Cookie",COOKIE);
|
|
|
96 |
httppost.addHeader("User-agent", USER_AGENT);
|
|
|
97 |
httppost.addHeader("Referer", "https://seller.flipkart.com/appV2");
|
|
|
98 |
|
|
|
99 |
StringEntity input = null;
|
|
|
100 |
input = new StringEntity(data);
|
|
|
101 |
input.setContentType("application/json");
|
|
|
102 |
httppost.setEntity(input);
|
|
|
103 |
HttpResponse response1 = null;
|
|
|
104 |
response1 = client.execute(httppost);
|
|
|
105 |
BufferedReader rd1 = null;
|
|
|
106 |
rd1 = new BufferedReader(new InputStreamReader(response1.getEntity().getContent()));
|
|
|
107 |
line= "";
|
|
|
108 |
StringBuilder sb = new StringBuilder();
|
|
|
109 |
while ((line = rd1.readLine()) != null) {
|
|
|
110 |
sb.append(line);
|
|
|
111 |
}
|
|
|
112 |
response1.getEntity().consumeContent();
|
|
|
113 |
JSONArray jsonArray = new JSONArray(sb.toString());
|
|
|
114 |
String listingId = "";
|
|
|
115 |
for (int i = 0, size = jsonArray.length(); i < size; i++){
|
|
|
116 |
JSONObject x = jsonArray.getJSONObject(i);
|
|
|
117 |
listingId = x.get("listing").toString();
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
data = getPostForSku(skuAtFlipkart, sellingPrice, listingId);
|
| 12828 |
kshitij.so |
121 |
logger.info(listingId);
|
| 12826 |
kshitij.so |
122 |
httppost = new HttpPost("https://seller.flipkart.com/sellerListing/listing/updateListings?sellerId=m2z93iskuj81qiid");
|
|
|
123 |
httppost.addHeader("Cookie",COOKIE);
|
|
|
124 |
httppost.addHeader("User-agent", USER_AGENT);
|
|
|
125 |
httppost.addHeader("Referer", "https://seller.flipkart.com/appV2");
|
|
|
126 |
|
|
|
127 |
input = null;
|
|
|
128 |
input = new StringEntity(data);
|
|
|
129 |
input.setContentType("application/json");
|
|
|
130 |
httppost.setEntity(input);
|
|
|
131 |
response1 = null;
|
|
|
132 |
response1 = client.execute(httppost);
|
|
|
133 |
rd1 = null;
|
|
|
134 |
rd1 = new BufferedReader(new InputStreamReader(response1.getEntity().getContent()));
|
|
|
135 |
line= "";
|
|
|
136 |
sb = new StringBuilder();
|
|
|
137 |
while ((line = rd1.readLine()) != null) {
|
|
|
138 |
sb.append(line);
|
|
|
139 |
}
|
|
|
140 |
System.out.println(sb.toString());
|
|
|
141 |
response1.getEntity().consumeContent();
|
|
|
142 |
jsonArray = new JSONArray(sb.toString());
|
|
|
143 |
String listingPrice = "";
|
|
|
144 |
for (int i = 0, size = jsonArray.length(); i < size; i++){
|
|
|
145 |
JSONObject x = jsonArray.getJSONObject(i);
|
|
|
146 |
listingPrice = x.get("listingPrice").toString();
|
|
|
147 |
}
|
| 12828 |
kshitij.so |
148 |
logger.info("New listing price "+listingPrice);
|
| 12834 |
kshitij.so |
149 |
System.out.println(Double.valueOf(sellingPrice));
|
|
|
150 |
System.out.println(Double.valueOf(listingPrice));
|
|
|
151 |
if (Double.valueOf(sellingPrice).equals(Double.valueOf(listingPrice))){
|
| 12826 |
kshitij.so |
152 |
return true;
|
|
|
153 |
}
|
|
|
154 |
return false;
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
public static String getPostForSku(String sku, String sellingPrice, String listingId){
|
|
|
159 |
return "{\"sellerId\":\""+SELLER_ID+"\"" +
|
|
|
160 |
",\"bulkListingRequest\":{\"listings\":" +
|
|
|
161 |
"[{\"listingId\":\""+listingId+"\",\"attributeValues\":" +
|
|
|
162 |
"{\"selling_price\":\""+sellingPrice+"\"},\"" +
|
|
|
163 |
"listingValidations\":" +
|
|
|
164 |
"{\"PRICE_ERROR_CHECK\":" +
|
|
|
165 |
"\"disable\"}}]}," +
|
|
|
166 |
"\"_csrf\":\""+CSRF+"\"}";
|
|
|
167 |
//return "{\"sellerId\":\"m2z93iskuj81qiid\",\"bulkListingRequest\":{\"listings\":[{\"listingId\":\"LSTACCDSN8FSJTTYPCQZWWGJL\",\"attributeValues\":{\"selling_price\":\"4901\"},\"listingValidations\":{\"PRICE_ERROR_CHECK\":\"enable\"}}]},\"_csrf\":\"wuru84MMNRMhRCWtlhydVdN9\"}";
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
public static void main(String[] args) throws ClientProtocolException, IOException, JSONException{
|
|
|
171 |
FlipkartPricingPannel fkPricing = new FlipkartPricingPannel();
|
| 12834 |
kshitij.so |
172 |
System.out.println(fkPricing.updatePrice("169","629"));
|
| 12826 |
kshitij.so |
173 |
}
|
|
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
}
|