Rev 12834 | Rev 13765 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.serving.services;import in.shop2020.config.ConfigException;import in.shop2020.thrift.clients.config.ConfigClient;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;import java.util.ArrayList;import java.util.List;import org.apache.http.HttpResponse;import org.apache.http.NameValuePair;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.HttpClient;import org.apache.http.client.entity.UrlEncodedFormEntity;import org.apache.http.client.methods.HttpGet;import org.apache.http.client.methods.HttpPost;import org.apache.http.entity.StringEntity;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.message.BasicNameValuePair;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class FlipkartPricingPannel{private static Logger logger = LoggerFactory.getLogger(FlipkartPricingPannel.class);public static final String AUTH_NAME = "flipkart";public static final String USER_NAME = "flipkart-support@saholic.com";public static final String PASSWORD = "076c27ee24d7596b06608a8ed2559f87";public static final String SELLER_ID = "m2z93iskuj81qiid";public static final String CSRF = "wuru84MMNRMhRCWtlhydVdN9";public static final String COOKIE = "T=TI141147280750274359991498309202525657388536723248248488328249492067; " +"__sonar=16983180403917152637; __gads=ID=c15eba68f7f44861:T=1411472817:S=ALNI_MYyU0QfJ923BqkcDhqFlRpZxMcA8w; " +"cmp_id=hp_dotd_4_DOTDOnBajajMixerGrinder_Sep23.|1414064820638; S=d1t16GpsIdt0JTsYuFF%2FMaE7jTGYozxMXM5a3ktJD24TBohceobkUv8l4GDr4KNLkLs5BOgnhsqkZNQRh2Lzrx%2B77zQ%3D%3D; " +"km_lv=x; __utma=19769839.1065606807.1411472808.1411472808.1411624009.2; __utmc=19769839; __utmz=19769839.1411472808.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);" +" s_cc=true; s_sq=%5B%5BB%5D%5D; prd_day=2|1411645620637; s_ppv=21; SN=2.VI89D3B4F7B5534B3C9EADE3BBD925875A.SI05ED43E07EAF40E9B4F265F5F2B1074D.VS141162400679268773093.1411624676;" +"VID=2.VI89D3B4F7B5534B3C9EADE3BBD925875A.1411624676.VS141162400679268773093; NSID=2.SI05ED43E07EAF40E9B4F265F5F2B1074D.1411624676.VI89D3B4F7B5534B3C9EADE3BBD925875A; " +"connect.sid=s%3AaUlfUN00goYPkqRHXtAbM6Nh.EBDDk9%2F0rQDXGb%2B23IEJ4QgrAgKFpXU%2FLOjuQyxJo44; is_login=true; sellerId=m2z93iskuj81qiid; __utma=143439159.1617147053.1411568832.1411568832.1411624688.2; " +"__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; " +"km_ni=m2z93iskuj81qiid; km_vs=1; km_uq=";public static final String SELLER_HOME = "seller.flipkart.com";public static final String USER_AGENT = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63";public static final HttpClient client = new DefaultHttpClient();private static String UPDATE_PRICE_ON_FK;static{try {UPDATE_PRICE_ON_FK = ConfigClient.getClient().get("sync_price_on_marketplace");} catch (ConfigException e) {logger.error("Unable to get sync prices on marketplace", e);UPDATE_PRICE_ON_FK = "false";}logger.info(UPDATE_PRICE_ON_FK);}public boolean updatePrice(String skuAtFlipkart, String sellingPrice) throws ClientProtocolException, IOException, JSONException{if (!Boolean.valueOf(UPDATE_PRICE_ON_FK)){return true;}HttpPost post = new HttpPost("https://seller.flipkart.com/login");BufferedReader rd= null;List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();nameValuePairs.add(new BasicNameValuePair("authName",AUTH_NAME));nameValuePairs.add(new BasicNameValuePair("username",USER_NAME));nameValuePairs.add(new BasicNameValuePair("password",PASSWORD));post.addHeader("Cookie",COOKIE);post.addHeader("User-agent", USER_AGENT);post.addHeader("Referer", SELLER_HOME);post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));HttpResponse response = client.execute(post);rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));String line="";while ((line = rd.readLine()) != null) {System.out.println(line);}String data = "{\"refiners\":{\"sku_id\":[\""+skuAtFlipkart+"\"]},\"verticalGroup\":{},\"sellerId\":\""+SELLER_ID+"\",\"pageSize\":10,\"pageNumber\":1,\"state\":\"LIVE\"}";//String data = "{\"refiners\":{\"sku_id\":[\"12442\"]},\"verticalGroup\":{},\"sellerId\":\"m2z93iskuj81qiid\",\"pageSize\":10,\"pageNumblogger.info(data);//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);HttpPost httppost = new HttpPost("https://seller.flipkart.com/sellerListing/listing/listingsForContext?sellerId=m2z93iskuj81qiid");httppost.addHeader("Cookie",COOKIE);httppost.addHeader("User-agent", USER_AGENT);httppost.addHeader("Referer", "https://seller.flipkart.com/appV2");StringEntity input = null;input = new StringEntity(data);input.setContentType("application/json");httppost.setEntity(input);HttpResponse response1 = null;response1 = client.execute(httppost);BufferedReader rd1 = null;rd1 = new BufferedReader(new InputStreamReader(response1.getEntity().getContent()));line= "";StringBuilder sb = new StringBuilder();while ((line = rd1.readLine()) != null) {sb.append(line);}response1.getEntity().consumeContent();JSONArray jsonArray = new JSONArray(sb.toString());String listingId = "";for (int i = 0, size = jsonArray.length(); i < size; i++){JSONObject x = jsonArray.getJSONObject(i);listingId = x.get("listing").toString();}data = getPostForSku(skuAtFlipkart, sellingPrice, listingId);logger.info(listingId);httppost = new HttpPost("https://seller.flipkart.com/sellerListing/listing/updateListings?sellerId=m2z93iskuj81qiid");httppost.addHeader("Cookie",COOKIE);httppost.addHeader("User-agent", USER_AGENT);httppost.addHeader("Referer", "https://seller.flipkart.com/appV2");input = null;input = new StringEntity(data);input.setContentType("application/json");httppost.setEntity(input);response1 = null;response1 = client.execute(httppost);rd1 = null;rd1 = new BufferedReader(new InputStreamReader(response1.getEntity().getContent()));line= "";sb = new StringBuilder();while ((line = rd1.readLine()) != null) {sb.append(line);}System.out.println(sb.toString());response1.getEntity().consumeContent();jsonArray = new JSONArray(sb.toString());String listingPrice = "";for (int i = 0, size = jsonArray.length(); i < size; i++){JSONObject x = jsonArray.getJSONObject(i);listingPrice = x.get("listingPrice").toString();}logger.info("New listing price "+listingPrice);if (Double.valueOf(sellingPrice).equals(Double.valueOf(listingPrice))){return true;}return false;}public static String getPostForSku(String sku, String sellingPrice, String listingId){return "{\"sellerId\":\""+SELLER_ID+"\"" +",\"bulkListingRequest\":{\"listings\":" +"[{\"listingId\":\""+listingId+"\",\"attributeValues\":" +"{\"selling_price\":\""+sellingPrice+"\"},\"" +"listingValidations\":" +"{\"PRICE_ERROR_CHECK\":" +"\"disable\"}}]}," +"\"_csrf\":\""+CSRF+"\"}";//return "{\"sellerId\":\"m2z93iskuj81qiid\",\"bulkListingRequest\":{\"listings\":[{\"listingId\":\"LSTACCDSN8FSJTTYPCQZWWGJL\",\"attributeValues\":{\"selling_price\":\"4901\"},\"listingValidations\":{\"PRICE_ERROR_CHECK\":\"enable\"}}]},\"_csrf\":\"wuru84MMNRMhRCWtlhydVdN9\"}";}public static void main(String[] args) throws ClientProtocolException, IOException, JSONException{FlipkartPricingPannel fkPricing = new FlipkartPricingPannel();System.out.println(fkPricing.updatePrice("169","629"));}}