| 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";
|
|
|
41 |
public static final String CSRF = "wuru84MMNRMhRCWtlhydVdN9";
|
| 13668 |
manish.sha |
42 |
public static String COOKIE ;
|
| 13784 |
manish.sha |
43 |
|
|
|
44 |
static String emailFromAddress;
|
|
|
45 |
static String password;
|
|
|
46 |
static GmailUtils mailer;
|
|
|
47 |
static String sendTo[];
|
|
|
48 |
|
|
|
49 |
|
| 12826 |
kshitij.so |
50 |
|
|
|
51 |
public static final String SELLER_HOME = "seller.flipkart.com";
|
|
|
52 |
public static final String USER_AGENT = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.63";
|
|
|
53 |
public static final HttpClient client = new DefaultHttpClient();
|
|
|
54 |
|
|
|
55 |
private static String UPDATE_PRICE_ON_FK;
|
|
|
56 |
|
|
|
57 |
static{
|
|
|
58 |
try {
|
|
|
59 |
UPDATE_PRICE_ON_FK = ConfigClient.getClient().get("sync_price_on_marketplace");
|
|
|
60 |
} catch (ConfigException e) {
|
|
|
61 |
logger.error("Unable to get sync prices on marketplace", e);
|
|
|
62 |
UPDATE_PRICE_ON_FK = "false";
|
|
|
63 |
}
|
| 12828 |
kshitij.so |
64 |
logger.info(UPDATE_PRICE_ON_FK);
|
| 13784 |
manish.sha |
65 |
|
|
|
66 |
emailFromAddress = "build@shop2020.in";
|
|
|
67 |
password = "cafe@nes";
|
|
|
68 |
mailer = new GmailUtils();
|
|
|
69 |
//sendTo = new String[]{"manish.sharma@shop2020.in"};
|
|
|
70 |
sendTo = new String[]{ "sandeep.sachdeva@shop2020.in", "manish.sharma@shop2020.in", "rajneesh.arora@shop2020.in",
|
|
|
71 |
"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
|
| 13792 |
manish.sha |
72 |
"yukti.jain@shop2020.in","yatin.singh@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","anikendra.das@shop2020.in"};
|
| 12826 |
kshitij.so |
73 |
}
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
public boolean updatePrice(String skuAtFlipkart, String sellingPrice) throws ClientProtocolException, IOException, JSONException{
|
|
|
77 |
|
| 12835 |
kshitij.so |
78 |
if (!Boolean.valueOf(UPDATE_PRICE_ON_FK)){
|
| 12826 |
kshitij.so |
79 |
return true;
|
|
|
80 |
}
|
|
|
81 |
|
| 13668 |
manish.sha |
82 |
HttpGet get_new;
|
|
|
83 |
BufferedReader rd= null;
|
|
|
84 |
get_new = new HttpGet("https://seller.flipkart.com/");
|
|
|
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 |
HttpResponse response = client.execute(get_new);
|
|
|
90 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
91 |
String line = "";
|
|
|
92 |
while ((line = rd.readLine()) != null) {
|
|
|
93 |
System.out.println(line);
|
|
|
94 |
}
|
|
|
95 |
COOKIE = response.getFirstHeader("Set-Cookie") == null ? "" :
|
|
|
96 |
response.getFirstHeader("Set-Cookie").getValue();
|
|
|
97 |
|
|
|
98 |
System.out.println("Cookies Before Login "+ COOKIE);
|
|
|
99 |
|
| 12826 |
kshitij.so |
100 |
HttpPost post = new HttpPost("https://seller.flipkart.com/login");
|
| 13668 |
manish.sha |
101 |
|
| 12826 |
kshitij.so |
102 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
103 |
nameValuePairs.add(new BasicNameValuePair("authName",
|
|
|
104 |
AUTH_NAME));
|
|
|
105 |
nameValuePairs.add(new BasicNameValuePair("username",
|
|
|
106 |
USER_NAME));
|
|
|
107 |
nameValuePairs.add(new BasicNameValuePair("password",
|
|
|
108 |
PASSWORD));
|
|
|
109 |
post.addHeader("Cookie",COOKIE);
|
|
|
110 |
post.addHeader("User-agent", USER_AGENT);
|
|
|
111 |
post.addHeader("Referer", SELLER_HOME);
|
|
|
112 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
| 13668 |
manish.sha |
113 |
response = client.execute(post);
|
|
|
114 |
COOKIE = response.getFirstHeader("Set-Cookie") == null ? "" :
|
|
|
115 |
response.getFirstHeader("Set-Cookie").getValue();
|
|
|
116 |
System.out.println("cookies "+COOKIE);
|
| 12826 |
kshitij.so |
117 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 13668 |
manish.sha |
118 |
line="";
|
| 12826 |
kshitij.so |
119 |
while ((line = rd.readLine()) != null) {
|
|
|
120 |
System.out.println(line);
|
|
|
121 |
}
|
|
|
122 |
String data = "{\"refiners\":{\"sku_id\":[\""+skuAtFlipkart+"\"]},\"verticalGroup\":{},\"sellerId\":\""+SELLER_ID+"\",\"pageSize\":10,\"pageNumber\":1,\"state\":\"LIVE\"}";
|
|
|
123 |
//String data = "{\"refiners\":{\"sku_id\":[\"12442\"]},\"verticalGroup\":{},\"sellerId\":\"m2z93iskuj81qiid\",\"pageSize\":10,\"pageNumb
|
| 12828 |
kshitij.so |
124 |
logger.info(data);
|
| 12826 |
kshitij.so |
125 |
//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);
|
|
|
126 |
HttpPost httppost = new HttpPost("https://seller.flipkart.com/sellerListing/listing/listingsForContext?sellerId=m2z93iskuj81qiid");
|
| 13668 |
manish.sha |
127 |
httppost.addHeader("Cookie",COOKIE+"; __utmt=1; __utma=143439159.1675929865.1422546011.1422546011.1422546011.1; __utmb=143439159.1.10.1422546011; __utmc=143439159; __utmz=143439159.1422546011.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); is_login=true; sellerId=m2z93iskuj81qiid");
|
| 12826 |
kshitij.so |
128 |
httppost.addHeader("User-agent", USER_AGENT);
|
|
|
129 |
httppost.addHeader("Referer", "https://seller.flipkart.com/appV2");
|
|
|
130 |
|
|
|
131 |
StringEntity input = null;
|
|
|
132 |
input = new StringEntity(data);
|
|
|
133 |
input.setContentType("application/json");
|
|
|
134 |
httppost.setEntity(input);
|
|
|
135 |
HttpResponse response1 = null;
|
|
|
136 |
response1 = client.execute(httppost);
|
|
|
137 |
BufferedReader rd1 = null;
|
|
|
138 |
rd1 = new BufferedReader(new InputStreamReader(response1.getEntity().getContent()));
|
|
|
139 |
line= "";
|
|
|
140 |
StringBuilder sb = new StringBuilder();
|
|
|
141 |
while ((line = rd1.readLine()) != null) {
|
|
|
142 |
sb.append(line);
|
|
|
143 |
}
|
|
|
144 |
response1.getEntity().consumeContent();
|
|
|
145 |
JSONArray jsonArray = new JSONArray(sb.toString());
|
|
|
146 |
String listingId = "";
|
|
|
147 |
for (int i = 0, size = jsonArray.length(); i < size; i++){
|
|
|
148 |
JSONObject x = jsonArray.getJSONObject(i);
|
|
|
149 |
listingId = x.get("listing").toString();
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
data = getPostForSku(skuAtFlipkart, sellingPrice, listingId);
|
| 12828 |
kshitij.so |
153 |
logger.info(listingId);
|
| 12826 |
kshitij.so |
154 |
httppost = new HttpPost("https://seller.flipkart.com/sellerListing/listing/updateListings?sellerId=m2z93iskuj81qiid");
|
| 13668 |
manish.sha |
155 |
httppost.addHeader("Cookie",COOKIE+"; __utmt=1; __utma=143439159.1675929865.1422546011.1422546011.1422546011.1; __utmb=143439159.1.10.1422546011; __utmc=143439159; __utmz=143439159.1422546011.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); is_login=true; sellerId=m2z93iskuj81qiid");
|
| 12826 |
kshitij.so |
156 |
httppost.addHeader("User-agent", USER_AGENT);
|
|
|
157 |
httppost.addHeader("Referer", "https://seller.flipkart.com/appV2");
|
|
|
158 |
|
|
|
159 |
input = null;
|
|
|
160 |
input = new StringEntity(data);
|
|
|
161 |
input.setContentType("application/json");
|
|
|
162 |
httppost.setEntity(input);
|
|
|
163 |
response1 = null;
|
|
|
164 |
response1 = client.execute(httppost);
|
|
|
165 |
rd1 = null;
|
|
|
166 |
rd1 = new BufferedReader(new InputStreamReader(response1.getEntity().getContent()));
|
|
|
167 |
line= "";
|
|
|
168 |
sb = new StringBuilder();
|
|
|
169 |
while ((line = rd1.readLine()) != null) {
|
|
|
170 |
sb.append(line);
|
|
|
171 |
}
|
|
|
172 |
System.out.println(sb.toString());
|
| 13784 |
manish.sha |
173 |
|
|
|
174 |
try {
|
|
|
175 |
mailer.sendSSLMessage(sendTo, "Flipkart Pricing Sent Response ", sb.toString(), emailFromAddress, password,new ArrayList<File>());
|
|
|
176 |
} catch (MessagingException e) {
|
|
|
177 |
e.printStackTrace();
|
|
|
178 |
}
|
| 12826 |
kshitij.so |
179 |
response1.getEntity().consumeContent();
|
|
|
180 |
jsonArray = new JSONArray(sb.toString());
|
|
|
181 |
String listingPrice = "";
|
|
|
182 |
for (int i = 0, size = jsonArray.length(); i < size; i++){
|
|
|
183 |
JSONObject x = jsonArray.getJSONObject(i);
|
|
|
184 |
listingPrice = x.get("listingPrice").toString();
|
|
|
185 |
}
|
| 12828 |
kshitij.so |
186 |
logger.info("New listing price "+listingPrice);
|
| 12834 |
kshitij.so |
187 |
if (Double.valueOf(sellingPrice).equals(Double.valueOf(listingPrice))){
|
| 12826 |
kshitij.so |
188 |
return true;
|
|
|
189 |
}
|
|
|
190 |
return false;
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
public static String getPostForSku(String sku, String sellingPrice, String listingId){
|
|
|
195 |
return "{\"sellerId\":\""+SELLER_ID+"\"" +
|
|
|
196 |
",\"bulkListingRequest\":{\"listings\":" +
|
|
|
197 |
"[{\"listingId\":\""+listingId+"\",\"attributeValues\":" +
|
|
|
198 |
"{\"selling_price\":\""+sellingPrice+"\"},\"" +
|
|
|
199 |
"listingValidations\":" +
|
|
|
200 |
"{\"PRICE_ERROR_CHECK\":" +
|
|
|
201 |
"\"disable\"}}]}," +
|
|
|
202 |
"\"_csrf\":\""+CSRF+"\"}";
|
|
|
203 |
//return "{\"sellerId\":\"m2z93iskuj81qiid\",\"bulkListingRequest\":{\"listings\":[{\"listingId\":\"LSTACCDSN8FSJTTYPCQZWWGJL\",\"attributeValues\":{\"selling_price\":\"4901\"},\"listingValidations\":{\"PRICE_ERROR_CHECK\":\"enable\"}}]},\"_csrf\":\"wuru84MMNRMhRCWtlhydVdN9\"}";
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
public static void main(String[] args) throws ClientProtocolException, IOException, JSONException{
|
|
|
207 |
FlipkartPricingPannel fkPricing = new FlipkartPricingPannel();
|
| 13765 |
manish.sha |
208 |
System.out.println(fkPricing.updatePrice("169","650"));
|
| 12826 |
kshitij.so |
209 |
}
|
|
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
}
|