| 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;
|
| 16088 |
manish.sha |
55 |
/*
|
| 12826 |
kshitij.so |
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"};
|
| 16088 |
manish.sha |
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{
|
| 16088 |
manish.sha |
111 |
/*
|
| 12835 |
kshitij.so |
112 |
if (!Boolean.valueOf(UPDATE_PRICE_ON_FK)){
|
| 12826 |
kshitij.so |
113 |
return true;
|
| 16088 |
manish.sha |
114 |
}*/
|
| 12826 |
kshitij.so |
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");
|
| 16088 |
manish.sha |
164 |
httppost.addHeader("Cookie",COOKIE+"; __gads=ID=dfe0374cf04d1576:T=1381304511:S=ALNI_Ma2TpDrlF9_amkoqp3MOYJBaFAOUg; km_lv=x; T=TI138130450866706710769873257251497444628820234222703981199700765991; __CG=u%3A6208250296506778000%2Cs%3A2098853214%2Ct%3A1419058011787%2Cc%3A1%2Ck%3Awww.flipkart.com/24/24/76%2Cf%3A0%2Ci%3A1; S=d1t13CXEVURPbRn%2FTAlMG9iwwwBWoS%2FUUixPxuJkY6W8pdfcWEzMG07x3EBPSRtlGHPdclpSYHdyFGacGJ0K01qpxtQ%3D%3D; __sonar=6631097455123118581; s_ch_list=%5B%5B'Affiliates'%2C'1436780663582'%5D%2C%5B'Direct%2528No%2520referrer%2529'%2C'1437154172975'%5D%5D; __utma=19769839.1156779613.1390806906.1436780662.1437154173.31; __utmz=19769839.1436780662.30.17.utmcsr=mobilehotindia.com|utmccn=(referral)|utmcmd=referral|utmcct=/r.html; VID=2.VIB4C4C187B63B4436AAE42944FD9BE1C9.1437389520.VS143738952083130426084; NSID=2.SI2B008083CC2145FFB103D6E76CDB343C.1437389520.VIB4C4C187B63B4436AAE42944FD9BE1C9; SN=2.VIB4C4C187B63B4436AAE42944FD9BE1C9.SI2B008083CC2145FFB103D6E76CDB343C.VS143738952083130426084.1437389520; __utmt=1; _gat=1; is_login=true; sellerId=m2z93iskuj81qiid; __utma=143439159.1156779613.1390806906.1435740037.1437454247.95; __utmb=143439159.7.9.1437454350458; __utmc=143439159; __utmz=143439159.1390806906.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _ga=GA1.2.1156779613.1390806906; _mkto_trk=id:021-QVV-957&token:_mch-flipkart.com-1434970574990-64308; kvcd=1437454400320; km_vs=1; km_ai=m2z93iskuj81qiid; km_ni=m2z93iskuj81qiid; km_uq=1437454437%20%2Fe%3Fcategory%3Dlistings%26label%3Dsearch%2520sku_id%2520in%2520my%2520listings%26_n%3Dsearch%2520listings%26_k%3D24a3ad2b74ad481059076b2c4d300b978b2c7adb%26_p%3Dm2z93iskuj81qiid%26_t%3D1437454437");
|
| 12826 |
kshitij.so |
165 |
httppost.addHeader("User-agent", USER_AGENT);
|
|
|
166 |
httppost.addHeader("Referer", "https://seller.flipkart.com/appV2");
|
| 16088 |
manish.sha |
167 |
httppost.addHeader("fk-csrf-token",csrfVal);
|
| 12826 |
kshitij.so |
168 |
|
|
|
169 |
StringEntity input = null;
|
|
|
170 |
input = new StringEntity(data);
|
|
|
171 |
input.setContentType("application/json");
|
|
|
172 |
httppost.setEntity(input);
|
|
|
173 |
HttpResponse response1 = null;
|
|
|
174 |
response1 = client.execute(httppost);
|
|
|
175 |
BufferedReader rd1 = null;
|
|
|
176 |
rd1 = new BufferedReader(new InputStreamReader(response1.getEntity().getContent()));
|
|
|
177 |
line= "";
|
|
|
178 |
StringBuilder sb = new StringBuilder();
|
|
|
179 |
while ((line = rd1.readLine()) != null) {
|
|
|
180 |
sb.append(line);
|
|
|
181 |
}
|
|
|
182 |
response1.getEntity().consumeContent();
|
| 15636 |
manish.sha |
183 |
System.out.println(sb.toString());
|
|
|
184 |
JSONObject jsonResult = new JSONObject(sb.toString());
|
|
|
185 |
JSONArray jsonResultArr = (JSONArray)(JSONArray)jsonResult.get("data");
|
|
|
186 |
String listingId = ((JSONObject)jsonResultArr.get(0)).get("listing").toString();
|
| 12826 |
kshitij.so |
187 |
|
| 15636 |
manish.sha |
188 |
data = getPostForSku(skuAtFlipkart, sellingPrice, listingId, csrfVal);
|
| 12828 |
kshitij.so |
189 |
logger.info(listingId);
|
| 12826 |
kshitij.so |
190 |
httppost = new HttpPost("https://seller.flipkart.com/sellerListing/listing/updateListings?sellerId=m2z93iskuj81qiid");
|
| 15899 |
manish.sha |
191 |
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 |
192 |
httppost.addHeader("User-agent", USER_AGENT);
|
|
|
193 |
httppost.addHeader("Referer", "https://seller.flipkart.com/appV2");
|
| 15636 |
manish.sha |
194 |
httppost.addHeader("fk-csrf-token",csrfVal);
|
| 12826 |
kshitij.so |
195 |
|
|
|
196 |
input = null;
|
|
|
197 |
input = new StringEntity(data);
|
|
|
198 |
input.setContentType("application/json");
|
|
|
199 |
httppost.setEntity(input);
|
|
|
200 |
response1 = null;
|
|
|
201 |
response1 = client.execute(httppost);
|
|
|
202 |
rd1 = null;
|
|
|
203 |
rd1 = new BufferedReader(new InputStreamReader(response1.getEntity().getContent()));
|
|
|
204 |
line= "";
|
|
|
205 |
sb = new StringBuilder();
|
|
|
206 |
while ((line = rd1.readLine()) != null) {
|
|
|
207 |
sb.append(line);
|
|
|
208 |
}
|
|
|
209 |
System.out.println(sb.toString());
|
| 13784 |
manish.sha |
210 |
|
|
|
211 |
try {
|
|
|
212 |
mailer.sendSSLMessage(sendTo, "Flipkart Pricing Sent Response ", sb.toString(), emailFromAddress, password,new ArrayList<File>());
|
|
|
213 |
} catch (MessagingException e) {
|
|
|
214 |
e.printStackTrace();
|
|
|
215 |
}
|
| 12826 |
kshitij.so |
216 |
response1.getEntity().consumeContent();
|
| 15636 |
manish.sha |
217 |
JSONArray jsonArray = new JSONArray(sb.toString());
|
| 12826 |
kshitij.so |
218 |
String listingPrice = "";
|
|
|
219 |
for (int i = 0, size = jsonArray.length(); i < size; i++){
|
|
|
220 |
JSONObject x = jsonArray.getJSONObject(i);
|
|
|
221 |
listingPrice = x.get("listingPrice").toString();
|
|
|
222 |
}
|
| 12828 |
kshitij.so |
223 |
logger.info("New listing price "+listingPrice);
|
| 12834 |
kshitij.so |
224 |
if (Double.valueOf(sellingPrice).equals(Double.valueOf(listingPrice))){
|
| 12826 |
kshitij.so |
225 |
return true;
|
|
|
226 |
}
|
|
|
227 |
return false;
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
|
| 15636 |
manish.sha |
231 |
public static String getPostForSku(String sku, String sellingPrice, String listingId, String csrf){
|
| 12826 |
kshitij.so |
232 |
return "{\"sellerId\":\""+SELLER_ID+"\"" +
|
|
|
233 |
",\"bulkListingRequest\":{\"listings\":" +
|
|
|
234 |
"[{\"listingId\":\""+listingId+"\",\"attributeValues\":" +
|
|
|
235 |
"{\"selling_price\":\""+sellingPrice+"\"},\"" +
|
|
|
236 |
"listingValidations\":" +
|
|
|
237 |
"{\"PRICE_ERROR_CHECK\":" +
|
|
|
238 |
"\"disable\"}}]}," +
|
| 15636 |
manish.sha |
239 |
"\"_csrf\":\""+csrf+"\"}";
|
| 12826 |
kshitij.so |
240 |
//return "{\"sellerId\":\"m2z93iskuj81qiid\",\"bulkListingRequest\":{\"listings\":[{\"listingId\":\"LSTACCDSN8FSJTTYPCQZWWGJL\",\"attributeValues\":{\"selling_price\":\"4901\"},\"listingValidations\":{\"PRICE_ERROR_CHECK\":\"enable\"}}]},\"_csrf\":\"wuru84MMNRMhRCWtlhydVdN9\"}";
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
public static void main(String[] args) throws ClientProtocolException, IOException, JSONException{
|
|
|
244 |
FlipkartPricingPannel fkPricing = new FlipkartPricingPannel();
|
| 13765 |
manish.sha |
245 |
System.out.println(fkPricing.updatePrice("169","650"));
|
| 12826 |
kshitij.so |
246 |
}
|
|
|
247 |
|
|
|
248 |
|
|
|
249 |
|
|
|
250 |
}
|