| 13584 |
manish.sha |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.order.FlipkartFCWarehouseLocation;
|
|
|
4 |
import in.shop2020.model.v1.order.FlipkartFaSalesSnapshot;
|
|
|
5 |
import in.shop2020.utils.EmailUtils;
|
|
|
6 |
import in.shop2020.utils.FlipkartConsumer;
|
|
|
7 |
import in.shop2020.utils.GmailUtils;
|
|
|
8 |
|
|
|
9 |
import java.io.BufferedReader;
|
|
|
10 |
import java.io.File;
|
|
|
11 |
import java.io.FileWriter;
|
|
|
12 |
import java.io.IOException;
|
|
|
13 |
import java.io.InputStreamReader;
|
|
|
14 |
import java.text.SimpleDateFormat;
|
|
|
15 |
import java.util.ArrayList;
|
|
|
16 |
import java.util.Calendar;
|
|
|
17 |
import java.util.Date;
|
|
|
18 |
import java.util.HashMap;
|
|
|
19 |
import java.util.List;
|
|
|
20 |
import java.util.Map;
|
|
|
21 |
|
|
|
22 |
import org.apache.http.HttpResponse;
|
|
|
23 |
import org.apache.http.NameValuePair;
|
|
|
24 |
import org.apache.http.client.ClientProtocolException;
|
|
|
25 |
import org.apache.http.client.HttpClient;
|
|
|
26 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
27 |
import org.apache.http.client.methods.HttpGet;
|
|
|
28 |
import org.apache.http.client.methods.HttpPost;
|
|
|
29 |
import org.apache.http.entity.StringEntity;
|
|
|
30 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
31 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
32 |
import org.json.JSONException;
|
|
|
33 |
import org.json.JSONObject;
|
|
|
34 |
import org.slf4j.Logger;
|
|
|
35 |
import org.slf4j.LoggerFactory;
|
|
|
36 |
|
|
|
37 |
import au.com.bytecode.opencsv.CSVReader;
|
|
|
38 |
import au.com.bytecode.opencsv.CSVWriter;
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
public class FlipkartFaSaleSnapshotGetter{
|
|
|
42 |
private static Logger logger = LoggerFactory.getLogger(FlipkartFaSaleSnapshotGetter .class);
|
|
|
43 |
private static HttpClient client = new DefaultHttpClient();
|
| 13668 |
manish.sha |
44 |
private static String cookies;
|
| 13584 |
manish.sha |
45 |
|
|
|
46 |
public static String getCsrfValue() throws ClientProtocolException, IOException, JSONException{
|
|
|
47 |
HttpResponse response;
|
|
|
48 |
|
|
|
49 |
BufferedReader rd= null;
|
|
|
50 |
HttpGet get_new;
|
|
|
51 |
|
|
|
52 |
String line = "";
|
|
|
53 |
|
| 13613 |
manish.sha |
54 |
get_new = new HttpGet("https://seller.flipkart.com/sfx");
|
| 15900 |
manish.sha |
55 |
get_new.addHeader("Cookie",cookies+"; 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=");
|
| 13668 |
manish.sha |
56 |
get_new.addHeader("Host","seller.flipkart.com");
|
|
|
57 |
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");
|
|
|
58 |
get_new.addHeader("Connection","keep-alive");
|
|
|
59 |
|
| 13584 |
manish.sha |
60 |
response = client.execute(get_new);
|
|
|
61 |
|
|
|
62 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
63 |
|
|
|
64 |
String csrfVal = "";
|
|
|
65 |
while ((line = rd.readLine()) != null) {
|
|
|
66 |
if(line.contains("var seller = ")){
|
|
|
67 |
String desiredLine = line;
|
|
|
68 |
desiredLine = desiredLine.split("var seller = ")[1].trim();
|
|
|
69 |
desiredLine = desiredLine.substring(0, desiredLine.length()-1);
|
|
|
70 |
System.out.println("desiredLine... "+desiredLine);
|
|
|
71 |
JSONObject jsonObj = new JSONObject(desiredLine);
|
|
|
72 |
|
|
|
73 |
csrfVal=(String)jsonObj.get("csrf");
|
|
|
74 |
System.out.println(csrfVal);
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
return csrfVal;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
public static void main(String[] args){
|
|
|
81 |
HttpPost post = new HttpPost("https://seller.flipkart.com/login");
|
|
|
82 |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
83 |
SimpleDateFormat repSdf = new SimpleDateFormat("MM-dd-yyyy");
|
|
|
84 |
SimpleDateFormat flipkartRepFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy");
|
|
|
85 |
Calendar cal1 = Calendar.getInstance();
|
|
|
86 |
Calendar cal2 = Calendar.getInstance();
|
| 13819 |
manish.sha |
87 |
cal1.add(Calendar.DAY_OF_MONTH, -4);
|
| 13584 |
manish.sha |
88 |
String startDate = sdf.format(cal1.getTime());
|
|
|
89 |
//cal2.add(Calendar.DAY_OF_MONTH, -1);
|
| 13817 |
manish.sha |
90 |
cal2.add(Calendar.DAY_OF_MONTH, 1);
|
| 13584 |
manish.sha |
91 |
String endDate = sdf.format(cal2.getTime());
|
|
|
92 |
cal1.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
93 |
String repStartDate = repSdf.format(cal1.getTime());
|
|
|
94 |
cal2.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
95 |
String repEndDate = repSdf.format(cal2.getTime());
|
|
|
96 |
BufferedReader rd= null;
|
|
|
97 |
Map<Date,Map<String,FlipkartFaSalesSnapshot>> orderDateItemIdFbaSaleSnapshotMap = new HashMap<Date,Map<String,FlipkartFaSalesSnapshot>>();
|
|
|
98 |
List<FlipkartFaSalesSnapshot> flipkartFaSalesSnapshotList = new ArrayList<FlipkartFaSalesSnapshot>();
|
|
|
99 |
Map<Long, Double> skuInventoryPriceMap = new HashMap<Long, Double>();
|
|
|
100 |
try {
|
| 13668 |
manish.sha |
101 |
HttpGet get_new;
|
|
|
102 |
get_new = new HttpGet("https://seller.flipkart.com/");
|
|
|
103 |
get_new.addHeader("Host","seller.flipkart.com");
|
|
|
104 |
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");
|
|
|
105 |
get_new.addHeader("Connection","keep-alive");
|
|
|
106 |
|
|
|
107 |
HttpResponse response = client.execute(get_new);
|
|
|
108 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
109 |
String line = "";
|
|
|
110 |
while ((line = rd.readLine()) != null) {
|
|
|
111 |
System.out.println(line);
|
|
|
112 |
}
|
|
|
113 |
cookies = response.getFirstHeader("Set-Cookie") == null ? "" :
|
|
|
114 |
response.getFirstHeader("Set-Cookie").getValue();
|
|
|
115 |
|
|
|
116 |
System.out.println("Cookies Before Login "+ cookies);
|
|
|
117 |
|
| 13584 |
manish.sha |
118 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
119 |
nameValuePairs.add(new BasicNameValuePair("authName",
|
|
|
120 |
"flipkart"));
|
|
|
121 |
nameValuePairs.add(new BasicNameValuePair("username",
|
|
|
122 |
"flipkart-support@saholic.com"));
|
|
|
123 |
nameValuePairs.add(new BasicNameValuePair("password",
|
|
|
124 |
"bestmobiledeals2010"));
|
| 13668 |
manish.sha |
125 |
post.addHeader("Cookie",cookies);
|
| 13584 |
manish.sha |
126 |
post.addHeader("User-agent", "Mozilla/4.0");
|
| 13668 |
manish.sha |
127 |
post.addHeader("Referer", "seller.flipkart.com");
|
| 13584 |
manish.sha |
128 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
| 13668 |
manish.sha |
129 |
response = client.execute(post);
|
|
|
130 |
cookies = response.getFirstHeader("Set-Cookie") == null ? "" :
|
|
|
131 |
response.getFirstHeader("Set-Cookie").getValue();
|
|
|
132 |
System.out.println("Cookies After Login "+cookies);
|
| 13584 |
manish.sha |
133 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 13668 |
manish.sha |
134 |
line = "";
|
|
|
135 |
|
| 13584 |
manish.sha |
136 |
while ((line = rd.readLine()) != null) {
|
|
|
137 |
System.out.println(line);
|
|
|
138 |
}
|
|
|
139 |
HttpPost post_1;
|
|
|
140 |
String csrfVal= getCsrfValue();
|
| 13602 |
manish.sha |
141 |
|
| 13584 |
manish.sha |
142 |
Thread.sleep(5000);
|
| 13602 |
manish.sha |
143 |
|
| 13584 |
manish.sha |
144 |
get_new = new HttpGet("https://seller.flipkart.com/sfx/inventory/stock/download?inventoryType=all&sellerId=m2z93iskuj81qiid&warehouse_id=del");
|
| 15900 |
manish.sha |
145 |
get_new.addHeader("Cookie",cookies+"; 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=");
|
| 13668 |
manish.sha |
146 |
get_new.addHeader("Host","seller.flipkart.com");
|
|
|
147 |
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");
|
|
|
148 |
get_new.addHeader("Connection","keep-alive");
|
|
|
149 |
|
| 13584 |
manish.sha |
150 |
response = client.execute(get_new);
|
|
|
151 |
|
|
|
152 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 13602 |
manish.sha |
153 |
|
| 13584 |
manish.sha |
154 |
CSVReader csvInventoryReader = new CSVReader(rd);
|
|
|
155 |
String[] values;
|
| 13611 |
manish.sha |
156 |
|
|
|
157 |
File inventoryFile = new File("/home/FAInventory.csv");
|
|
|
158 |
|
|
|
159 |
if(inventoryFile.exists()){
|
|
|
160 |
inventoryFile.delete();
|
|
|
161 |
}
|
| 13668 |
manish.sha |
162 |
int i=1;
|
| 13602 |
manish.sha |
163 |
|
| 13587 |
manish.sha |
164 |
CSVWriter writer = new CSVWriter(new FileWriter("/home/FAInventory.csv", true));
|
| 13584 |
manish.sha |
165 |
while ((values = csvInventoryReader.readNext()) != null) {
|
|
|
166 |
writer.writeNext(values);
|
|
|
167 |
if(i==1){
|
|
|
168 |
i++;
|
|
|
169 |
continue;
|
|
|
170 |
}
|
| 13961 |
manish.sha |
171 |
if(values[values.length-1].equalsIgnoreCase("FA")){
|
|
|
172 |
skuInventoryPriceMap.put(Long.parseLong(values[0]),Double.parseDouble(values[2]));
|
|
|
173 |
}
|
| 13584 |
manish.sha |
174 |
i++;
|
|
|
175 |
}
|
|
|
176 |
writer.close();
|
| 13602 |
manish.sha |
177 |
|
| 13584 |
manish.sha |
178 |
String paramVal = "{\"fromDate\":\""+startDate+"\",\"toDate\":\""+endDate+"\",\"warehouseId\":\"del\",\"type\":\"InvoiceReport\",\"_csrf\":\""+csrfVal+"\"}";
|
|
|
179 |
System.out.println(paramVal);
|
|
|
180 |
StringEntity entity = new StringEntity(paramVal, "utf-8");
|
| 13602 |
manish.sha |
181 |
|
|
|
182 |
|
| 13584 |
manish.sha |
183 |
post_1 = new HttpPost("https://seller.flipkart.com/sfx/reports/submit?sellerId=m2z93iskuj81qiid");
|
| 15900 |
manish.sha |
184 |
post_1.addHeader("Cookie",cookies+"; 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=");
|
| 13584 |
manish.sha |
185 |
post_1.addHeader("fk-csrf-token",csrfVal);
|
|
|
186 |
post_1.addHeader("Content-Type","application/json;charset=UTF-8");
|
|
|
187 |
post_1.addHeader("Host","seller.flipkart.com");
|
|
|
188 |
post_1.addHeader("Origin","https://seller.flipkart.com");
|
|
|
189 |
post_1.addHeader("Accept","application/json, text/plain, *//*");
|
|
|
190 |
post_1.addHeader("Accept-Language","en-US,en;q=0.8");
|
|
|
191 |
post_1.addHeader("Referer","https://seller.flipkart.com/sfx");
|
|
|
192 |
post_1.addHeader("User-Agent","Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36");
|
|
|
193 |
|
|
|
194 |
post_1.setEntity(entity);
|
|
|
195 |
|
|
|
196 |
response = client.execute(post_1);
|
| 13602 |
manish.sha |
197 |
|
| 13584 |
manish.sha |
198 |
response.getEntity().consumeContent();
|
|
|
199 |
|
|
|
200 |
Thread.sleep(120000);
|
| 13602 |
manish.sha |
201 |
|
| 13584 |
manish.sha |
202 |
//https://seller.flipkart.com/sfx/reports/download/?sellerId=m2z93iskuj81qiid&downloadurl=/reports/invoices/invoice_csv_m2z93iskuj81qiid_09-30-2014_10-30-2014/download_csv
|
| 16702 |
manish.sha |
203 |
get_new = new HttpGet("https://seller.flipkart.com/sfx/reports/download/?sellerId=m2z93iskuj81qiid&downloadurl=/reports/invoices/invoice_csv_m2z93iskuj81qiid_del_"+repStartDate+"_"+repEndDate+"/download_csv");
|
| 15764 |
manish.sha |
204 |
//https://seller.flipkart.com/sfx/reports/download/?sellerId=m2z93iskuj81qiid&downloadurl=/reports/invoices/invoice_csv_m2z93iskuj81qiid_03-28-2015_04-02-2015/download_csv
|
| 16702 |
manish.sha |
205 |
get_new.addHeader("Cookie",cookies+"; 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=");
|
| 16701 |
manish.sha |
206 |
//__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_ppv=26; s_cc=true; s_ch_list=%5B%5B'Referring%2520Domains'%2C'1440657700966'%5D%2C%5B'Referring%2520Domains'%2C'1440668738575'%5D%2C%5B'Referring%2520Domains'%2C'1440679269091'%5D%5D; __utma=19769839.1156779613.1390806906.1440668740.1440679270.35; __utmc=19769839; __utmz=19769839.1440679270.35.20.utmcsr=track.in.omgpm.com|utmccn=(referral)|utmcmd=referral|utmcct=/; SN=2.VIB4C4C187B63B4436AAE42944FD9BE1C9.SI2B008083CC2145FFB103D6E76CDB343C.VS144067926935821770173.1440679272; VID=2.VIB4C4C187B63B4436AAE42944FD9BE1C9.1440679272.VS144067926935821770173; NSID=2.SI2B008083CC2145FFB103D6E76CDB343C.1440679272.VIB4C4C187B63B4436AAE42944FD9BE1C9; s_sq=%5B%5BB%5D%5D; __utmt=1; is_login=true; sellerId=m2z93iskuj81qiid; __utma=143439159.1156779613.1390806906.1437454247.1441183861.96; __utmb=143439159.4.9.1441183877852; __utmc=143439159; __utmz=143439159.1390806906.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _gat=1; _ga=GA1.2.1156779613.1390806906; _mkto_trk=id:021-QVV-957&token:_mch-flipkart.com-1434970574990-64308; kvcd=1441183889041; km_ai=m2z93iskuj81qiid; km_ni=m2z93iskuj81qiid; km_vs=1; km_uq=
|
|
|
207 |
//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=");
|
| 13668 |
manish.sha |
208 |
get_new.addHeader("Host","seller.flipkart.com");
|
|
|
209 |
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");
|
|
|
210 |
get_new.addHeader("Connection","keep-alive");
|
|
|
211 |
|
| 13584 |
manish.sha |
212 |
response = client.execute(get_new);
|
|
|
213 |
|
| 13602 |
manish.sha |
214 |
|
| 13584 |
manish.sha |
215 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 13602 |
manish.sha |
216 |
|
| 13584 |
manish.sha |
217 |
i=1;
|
|
|
218 |
CSVReader csvReader = new CSVReader(rd);
|
| 16702 |
manish.sha |
219 |
|
| 13584 |
manish.sha |
220 |
while ((values = csvReader.readNext()) != null) {
|
|
|
221 |
if(i==1){
|
|
|
222 |
i++;
|
|
|
223 |
continue;
|
|
|
224 |
}
|
|
|
225 |
System.out.println(values[0]);
|
| 13602 |
manish.sha |
226 |
Date date = flipkartRepFormat.parse(values[5]);
|
| 13584 |
manish.sha |
227 |
Date date_key = sdf.parse(sdf.format(date));
|
| 13602 |
manish.sha |
228 |
if(!(values[12].equalsIgnoreCase("SalesInvoice")||values[12].equalsIgnoreCase("CourierReturnInvoice")||values[12].equalsIgnoreCase("CustomerReturnInvoice"))){
|
|
|
229 |
i++;
|
|
|
230 |
continue;
|
|
|
231 |
}
|
|
|
232 |
if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_key)){
|
|
|
233 |
FlipkartFaSalesSnapshot faSalesSnapshot;
|
|
|
234 |
if(orderDateItemIdFbaSaleSnapshotMap.get(date_key).containsKey(values[7])){
|
|
|
235 |
faSalesSnapshot = orderDateItemIdFbaSaleSnapshotMap.get(date_key).get(values[7]);
|
|
|
236 |
if(values[12].equalsIgnoreCase("SalesInvoice")){
|
|
|
237 |
faSalesSnapshot.setTotalOrderCount(faSalesSnapshot.getTotalOrderCount()+Integer.parseInt(values[13]));
|
|
|
238 |
faSalesSnapshot.setTotalSale(faSalesSnapshot.getTotalSale()+ Double.parseDouble(values[9]));
|
| 13584 |
manish.sha |
239 |
}
|
| 13602 |
manish.sha |
240 |
if(values[12].equalsIgnoreCase("CourierReturnInvoice")||values[12].equalsIgnoreCase("CustomerReturnInvoice")){
|
|
|
241 |
faSalesSnapshot.setTotalOrderCount(faSalesSnapshot.getTotalOrderCount()+0);
|
|
|
242 |
faSalesSnapshot.setTotalSale(faSalesSnapshot.getTotalSale()+0.0);
|
|
|
243 |
faSalesSnapshot.setReturnQuantity(faSalesSnapshot.getReturnQuantity()+Integer.parseInt(values[13]));
|
|
|
244 |
faSalesSnapshot.setReturnValue(faSalesSnapshot.getReturnValue()+Double.parseDouble(values[9]));
|
|
|
245 |
}
|
|
|
246 |
Map<String,FlipkartFaSalesSnapshot> itemIdFaSnapshotMap = orderDateItemIdFbaSaleSnapshotMap.get(date_key);
|
|
|
247 |
itemIdFaSnapshotMap.put(values[7], faSalesSnapshot);
|
|
|
248 |
orderDateItemIdFbaSaleSnapshotMap.put(date_key, itemIdFaSnapshotMap);
|
|
|
249 |
} else{
|
|
|
250 |
faSalesSnapshot = new FlipkartFaSalesSnapshot();
|
| 13584 |
manish.sha |
251 |
faSalesSnapshot.setDateOfSale(date_key.getTime());
|
|
|
252 |
faSalesSnapshot.setItem_id(Long.parseLong(values[7]));
|
|
|
253 |
faSalesSnapshot.setOurPrice(Double.parseDouble(values[9])/Double.parseDouble(values[13]));
|
|
|
254 |
if(values[12].equalsIgnoreCase("SalesInvoice")){
|
|
|
255 |
faSalesSnapshot.setTotalOrderCount(Integer.parseInt(values[13]));
|
|
|
256 |
faSalesSnapshot.setTotalSale(Double.parseDouble(values[9]));
|
| 13602 |
manish.sha |
257 |
}
|
|
|
258 |
if(values[12].equalsIgnoreCase("CourierReturnInvoice")||values[12].equalsIgnoreCase("CustomerReturnInvoice")){
|
| 13584 |
manish.sha |
259 |
faSalesSnapshot.setTotalOrderCount(0);
|
|
|
260 |
faSalesSnapshot.setTotalSale(0.0);
|
|
|
261 |
faSalesSnapshot.setReturnQuantity(Integer.parseInt(values[13]));
|
|
|
262 |
faSalesSnapshot.setReturnValue(Double.parseDouble(values[9]));
|
|
|
263 |
}
|
|
|
264 |
faSalesSnapshot.setFcLocation(FlipkartFCWarehouseLocation.Delhi);
|
|
|
265 |
faSalesSnapshot.setIsOutOfStock(false);
|
| 13602 |
manish.sha |
266 |
Map<String,FlipkartFaSalesSnapshot> itemIdFaSnapshotMap = orderDateItemIdFbaSaleSnapshotMap.get(date_key);
|
| 13584 |
manish.sha |
267 |
itemIdFaSnapshotMap.put(values[7], faSalesSnapshot);
|
|
|
268 |
orderDateItemIdFbaSaleSnapshotMap.put(date_key, itemIdFaSnapshotMap);
|
|
|
269 |
}
|
| 13602 |
manish.sha |
270 |
} else {
|
|
|
271 |
FlipkartFaSalesSnapshot faSalesSnapshot = new FlipkartFaSalesSnapshot();
|
|
|
272 |
faSalesSnapshot.setDateOfSale(date_key.getTime());
|
|
|
273 |
faSalesSnapshot.setItem_id(Long.parseLong(values[7]));
|
|
|
274 |
faSalesSnapshot.setOurPrice(Double.parseDouble(values[9])/Double.parseDouble(values[13]));
|
|
|
275 |
if(values[12].equalsIgnoreCase("SalesInvoice")){
|
|
|
276 |
faSalesSnapshot.setTotalOrderCount(Integer.parseInt(values[13]));
|
|
|
277 |
faSalesSnapshot.setTotalSale(Double.parseDouble(values[9]));
|
|
|
278 |
}
|
|
|
279 |
if(values[12].equalsIgnoreCase("CourierReturnInvoice")||values[12].equalsIgnoreCase("CustomerReturnInvoice")){
|
|
|
280 |
faSalesSnapshot.setTotalOrderCount(0);
|
|
|
281 |
faSalesSnapshot.setTotalSale(0.0);
|
|
|
282 |
faSalesSnapshot.setReturnQuantity(Integer.parseInt(values[13]));
|
|
|
283 |
faSalesSnapshot.setReturnValue(Double.parseDouble(values[9]));
|
|
|
284 |
}
|
|
|
285 |
faSalesSnapshot.setFcLocation(FlipkartFCWarehouseLocation.Delhi);
|
|
|
286 |
faSalesSnapshot.setIsOutOfStock(false);
|
|
|
287 |
Map<String,FlipkartFaSalesSnapshot> itemIdFaSnapshotMap = new HashMap<String,FlipkartFaSalesSnapshot>();
|
|
|
288 |
itemIdFaSnapshotMap.put(values[7], faSalesSnapshot);
|
|
|
289 |
orderDateItemIdFbaSaleSnapshotMap.put(date_key, itemIdFaSnapshotMap);
|
|
|
290 |
}
|
|
|
291 |
i++;
|
| 13584 |
manish.sha |
292 |
}
|
| 13602 |
manish.sha |
293 |
|
| 13584 |
manish.sha |
294 |
for(Long itemId : skuInventoryPriceMap.keySet()){
|
|
|
295 |
for(Date dateOfSale : orderDateItemIdFbaSaleSnapshotMap.keySet()){
|
|
|
296 |
if(orderDateItemIdFbaSaleSnapshotMap.get(dateOfSale).containsKey(itemId.toString())){
|
|
|
297 |
continue;
|
|
|
298 |
}else{
|
|
|
299 |
FlipkartFaSalesSnapshot faSalesSnapshot = new FlipkartFaSalesSnapshot();
|
|
|
300 |
faSalesSnapshot.setItem_id(itemId);
|
|
|
301 |
faSalesSnapshot.setDateOfSale(dateOfSale.getTime());
|
|
|
302 |
faSalesSnapshot.setOurPrice(skuInventoryPriceMap.get(itemId));
|
|
|
303 |
faSalesSnapshot.setTotalOrderCount(0);
|
|
|
304 |
faSalesSnapshot.setTotalSale(0.0);
|
|
|
305 |
faSalesSnapshot.setReturnQuantity(0);
|
|
|
306 |
faSalesSnapshot.setReturnValue(0.0);
|
|
|
307 |
faSalesSnapshot.setIsOutOfStock(true);
|
|
|
308 |
faSalesSnapshot.setFcLocation(FlipkartFCWarehouseLocation.Delhi);
|
|
|
309 |
orderDateItemIdFbaSaleSnapshotMap.get(dateOfSale).put(itemId.toString(), faSalesSnapshot);
|
|
|
310 |
}
|
|
|
311 |
}
|
|
|
312 |
}
|
| 13602 |
manish.sha |
313 |
|
| 13584 |
manish.sha |
314 |
for(Date dateOfSale : orderDateItemIdFbaSaleSnapshotMap.keySet()){
|
|
|
315 |
Map<String,FlipkartFaSalesSnapshot> itemIdFaSnapshotMap = orderDateItemIdFbaSaleSnapshotMap.get(dateOfSale);
|
|
|
316 |
for(String itemId : itemIdFaSnapshotMap.keySet()){
|
|
|
317 |
flipkartFaSalesSnapshotList.add(itemIdFaSnapshotMap.get(itemId));
|
|
|
318 |
}
|
|
|
319 |
}
|
|
|
320 |
boolean valuesUpdated = FlipkartConsumer.bulkAddOrUpdateFlipkartFbaSalesSnapshot(flipkartFaSalesSnapshotList);
|
| 13602 |
manish.sha |
321 |
|
| 13584 |
manish.sha |
322 |
if(valuesUpdated){
|
|
|
323 |
System.out.println("Values are updated");
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
}
|
|
|
327 |
catch(Exception e){
|
| 13612 |
manish.sha |
328 |
e.printStackTrace();
|
| 13587 |
manish.sha |
329 |
String[] sendTo = new String[] { "manish.sharma@shop2020.in","kshitij.sood@shop2020.in","amit.gupta@shop2020.in","anikendra.das@shop2020.in"};
|
| 13602 |
manish.sha |
330 |
String emailSubjectTxt = "Error while generating Flipkart Sale Snapshot";
|
|
|
331 |
String message = "Run FlipkartFaSaleSnapshotGetter in Common Project. \nSend all Flipkart Reports Again. \nJobs are configured at Support-backup Machine";
|
|
|
332 |
try {
|
|
|
333 |
GmailUtils mailer = new GmailUtils();
|
| 13620 |
manish.sha |
334 |
mailer.sendSSLMessage(sendTo, emailSubjectTxt, message, "build-staging@shop2020.in", "shop2020", new ArrayList<File>());
|
| 13602 |
manish.sha |
335 |
} catch (Exception ex) {
|
|
|
336 |
ex.printStackTrace();
|
|
|
337 |
|
|
|
338 |
}
|
| 13584 |
manish.sha |
339 |
}
|
|
|
340 |
}
|
|
|
341 |
}
|