| 12826 |
kshitij.so |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.config.ConfigException;
|
|
|
4 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 13784 |
manish.sha |
5 |
import in.shop2020.utils.GmailUtils;
|
| 12826 |
kshitij.so |
6 |
|
|
|
7 |
import java.io.BufferedReader;
|
| 13784 |
manish.sha |
8 |
import java.io.File;
|
| 12826 |
kshitij.so |
9 |
import java.io.IOException;
|
|
|
10 |
import java.io.InputStreamReader;
|
|
|
11 |
import java.io.UnsupportedEncodingException;
|
|
|
12 |
import java.util.ArrayList;
|
|
|
13 |
import java.util.List;
|
|
|
14 |
|
| 13784 |
manish.sha |
15 |
import javax.mail.MessagingException;
|
|
|
16 |
|
| 12826 |
kshitij.so |
17 |
import org.apache.http.HttpResponse;
|
|
|
18 |
import org.apache.http.NameValuePair;
|
|
|
19 |
import org.apache.http.client.ClientProtocolException;
|
|
|
20 |
import org.apache.http.client.HttpClient;
|
|
|
21 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
22 |
import org.apache.http.client.methods.HttpGet;
|
|
|
23 |
import org.apache.http.client.methods.HttpPost;
|
|
|
24 |
import org.apache.http.entity.StringEntity;
|
|
|
25 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
26 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
27 |
import org.json.JSONArray;
|
|
|
28 |
import org.json.JSONException;
|
|
|
29 |
import org.json.JSONObject;
|
|
|
30 |
import org.slf4j.Logger;
|
|
|
31 |
import org.slf4j.LoggerFactory;
|
|
|
32 |
|
|
|
33 |
public class FlipkartPricingPannel{
|
|
|
34 |
|
|
|
35 |
private static Logger logger = LoggerFactory.getLogger(FlipkartPricingPannel.class);
|
|
|
36 |
|
|
|
37 |
public static final String AUTH_NAME = "flipkart";
|
|
|
38 |
public static final String USER_NAME = "flipkart-support@saholic.com";
|
| 13765 |
manish.sha |
39 |
public static final String PASSWORD = "bestmobiledeals2010";
|
| 12826 |
kshitij.so |
40 |
public static final String SELLER_ID = "m2z93iskuj81qiid";
|
| 13668 |
manish.sha |
41 |
public static String COOKIE ;
|
| 13784 |
manish.sha |
42 |
|
|
|
43 |
static String emailFromAddress;
|
|
|
44 |
static String password;
|
|
|
45 |
static GmailUtils mailer;
|
|
|
46 |
static String sendTo[];
|
|
|
47 |
|
|
|
48 |
|
| 12826 |
kshitij.so |
49 |
|
|
|
50 |
public static final String SELLER_HOME = "seller.flipkart.com";
|
|
|
51 |
public static final String USER_AGENT = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63";
|
|
|
52 |
public static final HttpClient client = new DefaultHttpClient();
|
|
|
53 |
|
|
|
54 |
private static String UPDATE_PRICE_ON_FK;
|
|
|
55 |
|
|
|
56 |
static{
|
|
|
57 |
try {
|
|
|
58 |
UPDATE_PRICE_ON_FK = ConfigClient.getClient().get("sync_price_on_marketplace");
|
|
|
59 |
} catch (ConfigException e) {
|
|
|
60 |
logger.error("Unable to get sync prices on marketplace", e);
|
|
|
61 |
UPDATE_PRICE_ON_FK = "false";
|
|
|
62 |
}
|
| 12828 |
kshitij.so |
63 |
logger.info(UPDATE_PRICE_ON_FK);
|
| 13784 |
manish.sha |
64 |
|
|
|
65 |
emailFromAddress = "build@shop2020.in";
|
|
|
66 |
password = "cafe@nes";
|
|
|
67 |
mailer = new GmailUtils();
|
|
|
68 |
//sendTo = new String[]{"manish.sharma@shop2020.in"};
|
|
|
69 |
sendTo = new String[]{ "sandeep.sachdeva@shop2020.in", "manish.sharma@shop2020.in", "rajneesh.arora@shop2020.in",
|
|
|
70 |
"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
|
| 13792 |
manish.sha |
71 |
"yukti.jain@shop2020.in","yatin.singh@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","anikendra.das@shop2020.in"};
|
| 12826 |
kshitij.so |
72 |
}
|
| 15636 |
manish.sha |
73 |
|
|
|
74 |
public static String getCsrfValue() throws ClientProtocolException, IOException, JSONException{
|
|
|
75 |
HttpResponse response;
|
|
|
76 |
|
|
|
77 |
BufferedReader rd= null;
|
|
|
78 |
HttpGet get_new;
|
|
|
79 |
|
|
|
80 |
String line = "";
|
|
|
81 |
|
|
|
82 |
get_new = new HttpGet("https://seller.flipkart.com/sfx");
|
| 15899 |
manish.sha |
83 |
get_new.addHeader("Cookie",COOKIE+"; T=TI143676574953728283468652963707792772000507925594940705902272051229; s_ppv=20; __utma=19769839.1606715935.1436765752.1436776227.1436781309.4; __utmc=19769839; s_cc=true; s_ch_list=%5B%5B'Affiliates'%2C'1436765752631'%5D%2C%5B'Direct%2528No%2520referrer%2529'%2C'1436772820483'%5D%2C%5B'Affiliates'%2C'1436776225673'%5D%2C%5B'Affiliates'%2C'1436781310176'%5D%5D; s_sq=%5B%5BB%5D%5D; SN=2.VI867C5C7412964CF699334DBD9EF6DE52.SIA588536C11BE409DA6EDA6421E4C553A.VS143678130317178984193.1436781310; VID=2.VI867C5C7412964CF699334DBD9EF6DE52.1436781310.VS143678130317178984193; NSID=2.SIA588536C11BE409DA6EDA6421E4C553A.1436781310.VI867C5C7412964CF699334DBD9EF6DE52; is_login=true; sellerId=m2z93iskuj81qiid; __utma=143439159.1310095091.1436782302.1436782302.1436782302.1; __utmb=143439159.3.9.1436782338363; __utmc=143439159; __utmz=143439159.1436782302.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); km_lv=x; _ga=GA1.2.1310095091.1436782302; _mkto_trk=id:021-QVV-957&token:_mch-flipkart.com-1436782303258-56348; kvcd=1436783491524; km_vs=1; km_ai=m2z93iskuj81qiid; km_ni=m2z93iskuj81qiid; km_uq=");
|
|
|
84 |
|
| 15636 |
manish.sha |
85 |
get_new.addHeader("Host","seller.flipkart.com");
|
|
|
86 |
get_new.addHeader("User-agent", "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31");
|
|
|
87 |
get_new.addHeader("Connection","keep-alive");
|
|
|
88 |
|
|
|
89 |
response = client.execute(get_new);
|
| 12826 |
kshitij.so |
90 |
|
| 15636 |
manish.sha |
91 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 12826 |
kshitij.so |
92 |
|
| 15636 |
manish.sha |
93 |
String csrfVal = "";
|
|
|
94 |
while ((line = rd.readLine()) != null) {
|
|
|
95 |
if(line.contains("var seller = ")){
|
|
|
96 |
String desiredLine = line;
|
|
|
97 |
desiredLine = desiredLine.split("var seller = ")[1].trim();
|
|
|
98 |
desiredLine = desiredLine.substring(0, desiredLine.length()-1);
|
|
|
99 |
System.out.println("desiredLine... "+desiredLine);
|
|
|
100 |
JSONObject jsonObj = new JSONObject(desiredLine);
|
|
|
101 |
|
|
|
102 |
csrfVal=(String)jsonObj.get("csrf");
|
|
|
103 |
System.out.println(csrfVal);
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
return csrfVal;
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
|
| 12826 |
kshitij.so |
110 |
public boolean updatePrice(String skuAtFlipkart, String sellingPrice) throws ClientProtocolException, IOException, JSONException{
|
|
|
111 |
|
| 12835 |
kshitij.so |
112 |
if (!Boolean.valueOf(UPDATE_PRICE_ON_FK)){
|
| 12826 |
kshitij.so |
113 |
return true;
|
|
|
114 |
}
|
|
|
115 |
|
| 13668 |
manish.sha |
116 |
HttpGet get_new;
|
|
|
117 |
BufferedReader rd= null;
|
|
|
118 |
get_new = new HttpGet("https://seller.flipkart.com/");
|
|
|
119 |
get_new.addHeader("Host","seller.flipkart.com");
|
|
|
120 |
get_new.addHeader("User-agent", "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63 Safari/537.31");
|
|
|
121 |
get_new.addHeader("Connection","keep-alive");
|
|
|
122 |
|
|
|
123 |
HttpResponse response = client.execute(get_new);
|
|
|
124 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
125 |
String line = "";
|
|
|
126 |
while ((line = rd.readLine()) != null) {
|
|
|
127 |
System.out.println(line);
|
|
|
128 |
}
|
|
|
129 |
COOKIE = response.getFirstHeader("Set-Cookie") == null ? "" :
|
|
|
130 |
response.getFirstHeader("Set-Cookie").getValue();
|
|
|
131 |
|
|
|
132 |
System.out.println("Cookies Before Login "+ COOKIE);
|
|
|
133 |
|
| 12826 |
kshitij.so |
134 |
HttpPost post = new HttpPost("https://seller.flipkart.com/login");
|
| 13668 |
manish.sha |
135 |
|
| 12826 |
kshitij.so |
136 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
137 |
nameValuePairs.add(new BasicNameValuePair("authName",
|
|
|
138 |
AUTH_NAME));
|
|
|
139 |
nameValuePairs.add(new BasicNameValuePair("username",
|
|
|
140 |
USER_NAME));
|
|
|
141 |
nameValuePairs.add(new BasicNameValuePair("password",
|
|
|
142 |
PASSWORD));
|
|
|
143 |
post.addHeader("Cookie",COOKIE);
|
|
|
144 |
post.addHeader("User-agent", USER_AGENT);
|
|
|
145 |
post.addHeader("Referer", SELLER_HOME);
|
|
|
146 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
| 13668 |
manish.sha |
147 |
response = client.execute(post);
|
|
|
148 |
COOKIE = response.getFirstHeader("Set-Cookie") == null ? "" :
|
|
|
149 |
response.getFirstHeader("Set-Cookie").getValue();
|
|
|
150 |
System.out.println("cookies "+COOKIE);
|
| 12826 |
kshitij.so |
151 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 13668 |
manish.sha |
152 |
line="";
|
| 12826 |
kshitij.so |
153 |
while ((line = rd.readLine()) != null) {
|
|
|
154 |
System.out.println(line);
|
|
|
155 |
}
|
| 15636 |
manish.sha |
156 |
|
|
|
157 |
String csrfVal= getCsrfValue();
|
|
|
158 |
|
|
|
159 |
String data = "{\"refiners\":{\"sku_id\":[\""+skuAtFlipkart+"\"]},\"verticalGroup\":{},\"sellerId\":\""+SELLER_ID+"\",\"pageSize\":10,\"pageNumber\":1,\"state\":\"LIVE\",\"_csrf\":\""+csrfVal+"\"}";
|
| 12826 |
kshitij.so |
160 |
//String data = "{\"refiners\":{\"sku_id\":[\"12442\"]},\"verticalGroup\":{},\"sellerId\":\"m2z93iskuj81qiid\",\"pageSize\":10,\"pageNumb
|
| 12828 |
kshitij.so |
161 |
logger.info(data);
|
| 12826 |
kshitij.so |
162 |
//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);
|
| 15625 |
manish.sha |
163 |
HttpPost httppost = new HttpPost("https://seller.flipkart.com/createproduct/getproductrowsforstate?sellerId=m2z93iskuj81qiid");
|
| 15899 |
manish.sha |
164 |
httppost.addHeader("Cookie",COOKIE+"; T=TI143676574953728283468652963707792772000507925594940705902272051229; s_ppv=20; __utma=19769839.1606715935.1436765752.1436776227.1436781309.4; __utmc=19769839; s_cc=true; s_ch_list=%5B%5B'Affiliates'%2C'1436765752631'%5D%2C%5B'Direct%2528No%2520referrer%2529'%2C'1436772820483'%5D%2C%5B'Affiliates'%2C'1436776225673'%5D%2C%5B'Affiliates'%2C'1436781310176'%5D%5D; s_sq=%5B%5BB%5D%5D; SN=2.VI867C5C7412964CF699334DBD9EF6DE52.SIA588536C11BE409DA6EDA6421E4C553A.VS143678130317178984193.1436781310; VID=2.VI867C5C7412964CF699334DBD9EF6DE52.1436781310.VS143678130317178984193; NSID=2.SIA588536C11BE409DA6EDA6421E4C553A.1436781310.VI867C5C7412964CF699334DBD9EF6DE52; is_login=true; sellerId=m2z93iskuj81qiid; __utma=143439159.1310095091.1436782302.1436782302.1436782302.1; __utmb=143439159.3.9.1436782338363; __utmc=143439159; __utmz=143439159.1436782302.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); km_lv=x; _ga=GA1.2.1310095091.1436782302; _mkto_trk=id:021-QVV-957&token:_mch-flipkart.com-1436782303258-56348; kvcd=1436783491524; km_vs=1; km_ai=m2z93iskuj81qiid; km_ni=m2z93iskuj81qiid; km_uq=");
|
| 12826 |
kshitij.so |
165 |
httppost.addHeader("User-agent", USER_AGENT);
|
|
|
166 |
httppost.addHeader("Referer", "https://seller.flipkart.com/appV2");
|
|
|
167 |
|
|
|
168 |
StringEntity input = null;
|
|
|
169 |
input = new StringEntity(data);
|
|
|
170 |
input.setContentType("application/json");
|
|
|
171 |
httppost.setEntity(input);
|
|
|
172 |
HttpResponse response1 = null;
|
|
|
173 |
response1 = client.execute(httppost);
|
|
|
174 |
BufferedReader rd1 = null;
|
|
|
175 |
rd1 = new BufferedReader(new InputStreamReader(response1.getEntity().getContent()));
|
|
|
176 |
line= "";
|
|
|
177 |
StringBuilder sb = new StringBuilder();
|
|
|
178 |
while ((line = rd1.readLine()) != null) {
|
|
|
179 |
sb.append(line);
|
|
|
180 |
}
|
|
|
181 |
response1.getEntity().consumeContent();
|
| 15636 |
manish.sha |
182 |
System.out.println(sb.toString());
|
|
|
183 |
JSONObject jsonResult = new JSONObject(sb.toString());
|
|
|
184 |
JSONArray jsonResultArr = (JSONArray)(JSONArray)jsonResult.get("data");
|
|
|
185 |
String listingId = ((JSONObject)jsonResultArr.get(0)).get("listing").toString();
|
| 12826 |
kshitij.so |
186 |
|
| 15636 |
manish.sha |
187 |
data = getPostForSku(skuAtFlipkart, sellingPrice, listingId, csrfVal);
|
| 12828 |
kshitij.so |
188 |
logger.info(listingId);
|
| 12826 |
kshitij.so |
189 |
httppost = new HttpPost("https://seller.flipkart.com/sellerListing/listing/updateListings?sellerId=m2z93iskuj81qiid");
|
| 15899 |
manish.sha |
190 |
httppost.addHeader("Cookie",COOKIE+"; T=TI143676574953728283468652963707792772000507925594940705902272051229; s_ppv=20; __utma=19769839.1606715935.1436765752.1436776227.1436781309.4; __utmc=19769839; s_cc=true; s_ch_list=%5B%5B'Affiliates'%2C'1436765752631'%5D%2C%5B'Direct%2528No%2520referrer%2529'%2C'1436772820483'%5D%2C%5B'Affiliates'%2C'1436776225673'%5D%2C%5B'Affiliates'%2C'1436781310176'%5D%5D; s_sq=%5B%5BB%5D%5D; SN=2.VI867C5C7412964CF699334DBD9EF6DE52.SIA588536C11BE409DA6EDA6421E4C553A.VS143678130317178984193.1436781310; VID=2.VI867C5C7412964CF699334DBD9EF6DE52.1436781310.VS143678130317178984193; NSID=2.SIA588536C11BE409DA6EDA6421E4C553A.1436781310.VI867C5C7412964CF699334DBD9EF6DE52; is_login=true; sellerId=m2z93iskuj81qiid; __utma=143439159.1310095091.1436782302.1436782302.1436782302.1; __utmb=143439159.3.9.1436782338363; __utmc=143439159; __utmz=143439159.1436782302.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); km_lv=x; _ga=GA1.2.1310095091.1436782302; _mkto_trk=id:021-QVV-957&token:_mch-flipkart.com-1436782303258-56348; kvcd=1436783491524; km_vs=1; km_ai=m2z93iskuj81qiid; km_ni=m2z93iskuj81qiid; km_uq=");
|
| 12826 |
kshitij.so |
191 |
httppost.addHeader("User-agent", USER_AGENT);
|
|
|
192 |
httppost.addHeader("Referer", "https://seller.flipkart.com/appV2");
|
| 15636 |
manish.sha |
193 |
httppost.addHeader("fk-csrf-token",csrfVal);
|
| 12826 |
kshitij.so |
194 |
|
|
|
195 |
input = null;
|
|
|
196 |
input = new StringEntity(data);
|
|
|
197 |
input.setContentType("application/json");
|
|
|
198 |
httppost.setEntity(input);
|
|
|
199 |
response1 = null;
|
|
|
200 |
response1 = client.execute(httppost);
|
|
|
201 |
rd1 = null;
|
|
|
202 |
rd1 = new BufferedReader(new InputStreamReader(response1.getEntity().getContent()));
|
|
|
203 |
line= "";
|
|
|
204 |
sb = new StringBuilder();
|
|
|
205 |
while ((line = rd1.readLine()) != null) {
|
|
|
206 |
sb.append(line);
|
|
|
207 |
}
|
|
|
208 |
System.out.println(sb.toString());
|
| 13784 |
manish.sha |
209 |
|
|
|
210 |
try {
|
|
|
211 |
mailer.sendSSLMessage(sendTo, "Flipkart Pricing Sent Response ", sb.toString(), emailFromAddress, password,new ArrayList<File>());
|
|
|
212 |
} catch (MessagingException e) {
|
|
|
213 |
e.printStackTrace();
|
|
|
214 |
}
|
| 12826 |
kshitij.so |
215 |
response1.getEntity().consumeContent();
|
| 15636 |
manish.sha |
216 |
JSONArray jsonArray = new JSONArray(sb.toString());
|
| 12826 |
kshitij.so |
217 |
String listingPrice = "";
|
|
|
218 |
for (int i = 0, size = jsonArray.length(); i < size; i++){
|
|
|
219 |
JSONObject x = jsonArray.getJSONObject(i);
|
|
|
220 |
listingPrice = x.get("listingPrice").toString();
|
|
|
221 |
}
|
| 12828 |
kshitij.so |
222 |
logger.info("New listing price "+listingPrice);
|
| 12834 |
kshitij.so |
223 |
if (Double.valueOf(sellingPrice).equals(Double.valueOf(listingPrice))){
|
| 12826 |
kshitij.so |
224 |
return true;
|
|
|
225 |
}
|
|
|
226 |
return false;
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
|
| 15636 |
manish.sha |
230 |
public static String getPostForSku(String sku, String sellingPrice, String listingId, String csrf){
|
| 12826 |
kshitij.so |
231 |
return "{\"sellerId\":\""+SELLER_ID+"\"" +
|
|
|
232 |
",\"bulkListingRequest\":{\"listings\":" +
|
|
|
233 |
"[{\"listingId\":\""+listingId+"\",\"attributeValues\":" +
|
|
|
234 |
"{\"selling_price\":\""+sellingPrice+"\"},\"" +
|
|
|
235 |
"listingValidations\":" +
|
|
|
236 |
"{\"PRICE_ERROR_CHECK\":" +
|
|
|
237 |
"\"disable\"}}]}," +
|
| 15636 |
manish.sha |
238 |
"\"_csrf\":\""+csrf+"\"}";
|
| 12826 |
kshitij.so |
239 |
//return "{\"sellerId\":\"m2z93iskuj81qiid\",\"bulkListingRequest\":{\"listings\":[{\"listingId\":\"LSTACCDSN8FSJTTYPCQZWWGJL\",\"attributeValues\":{\"selling_price\":\"4901\"},\"listingValidations\":{\"PRICE_ERROR_CHECK\":\"enable\"}}]},\"_csrf\":\"wuru84MMNRMhRCWtlhydVdN9\"}";
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
public static void main(String[] args) throws ClientProtocolException, IOException, JSONException{
|
|
|
243 |
FlipkartPricingPannel fkPricing = new FlipkartPricingPannel();
|
| 13765 |
manish.sha |
244 |
System.out.println(fkPricing.updatePrice("169","650"));
|
| 12826 |
kshitij.so |
245 |
}
|
|
|
246 |
|
|
|
247 |
|
|
|
248 |
|
|
|
249 |
}
|