| 9651 |
manish.sha |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 12427 |
manish.sha |
4 |
import in.shop2020.utils.GmailUtils;
|
| 9651 |
manish.sha |
5 |
|
|
|
6 |
import java.io.BufferedReader;
|
|
|
7 |
import java.io.InputStreamReader;
|
|
|
8 |
import java.text.SimpleDateFormat;
|
|
|
9 |
import java.util.ArrayList;
|
| 12515 |
manish.sha |
10 |
import java.util.Calendar;
|
| 9651 |
manish.sha |
11 |
import java.util.List;
|
|
|
12 |
|
| 12427 |
manish.sha |
13 |
import javax.mail.MessagingException;
|
|
|
14 |
|
| 9651 |
manish.sha |
15 |
import org.apache.http.HttpResponse;
|
|
|
16 |
import org.apache.http.NameValuePair;
|
|
|
17 |
import org.apache.http.client.HttpClient;
|
|
|
18 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
19 |
import org.apache.http.client.methods.HttpGet;
|
|
|
20 |
import org.apache.http.client.methods.HttpPost;
|
|
|
21 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
22 |
import org.apache.http.message.BasicNameValuePair;
|
| 12427 |
manish.sha |
23 |
import org.json.JSONArray;
|
|
|
24 |
import org.json.JSONObject;
|
| 9651 |
manish.sha |
25 |
|
|
|
26 |
public class FlipkartOrderStatusReconciliation{
|
| 12427 |
manish.sha |
27 |
static String emailFromAddress;
|
|
|
28 |
static String password;
|
|
|
29 |
static GmailUtils mailer;
|
|
|
30 |
static String sendTo[];
|
| 13668 |
manish.sha |
31 |
private static String cookies;
|
| 12516 |
manish.sha |
32 |
|
| 12427 |
manish.sha |
33 |
static {
|
|
|
34 |
emailFromAddress = "build-staging@shop2020.in";
|
|
|
35 |
password = "shop2020";
|
|
|
36 |
mailer = new GmailUtils();
|
|
|
37 |
sendTo = new String[] { "kshitij.sood@shop2020.in", "manish.sharma@shop2020.in", "amit.gupta@shop2020.in" };
|
|
|
38 |
}
|
| 12516 |
manish.sha |
39 |
|
| 12427 |
manish.sha |
40 |
public static void main(String[] args) throws MessagingException {
|
| 9651 |
manish.sha |
41 |
HttpClient client = new DefaultHttpClient();
|
|
|
42 |
HttpPost post = new HttpPost("https://seller.flipkart.com/login");
|
|
|
43 |
BufferedReader rd= null;
|
| 12516 |
manish.sha |
44 |
|
| 9651 |
manish.sha |
45 |
List<List<String>> deliveredOrderDataList = new ArrayList<List<String>>();
|
|
|
46 |
SimpleDateFormat gotFlipkartDateFormat = new SimpleDateFormat("MMM dd, yyyy");
|
| 9699 |
manish.sha |
47 |
//SimpleDateFormat createDateFormatter = new SimpleDateFormat("MMM dd, yyyy hh:mm aaa");
|
| 9651 |
manish.sha |
48 |
SimpleDateFormat ourDBDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| 9698 |
manish.sha |
49 |
long minCreationDate = 0l;
|
| 9651 |
manish.sha |
50 |
try {
|
| 12515 |
manish.sha |
51 |
/*minCreationDate = 1386432631000l;new TransactionClient().getClient().getMinCreatedTimeStampUndeliveredOrdersForSource(OrderSource.FLIPKART.getValue());*/
|
|
|
52 |
Calendar cal = Calendar.getInstance();
|
| 12540 |
manish.sha |
53 |
cal.add(Calendar.DAY_OF_MONTH, -30);
|
| 12515 |
manish.sha |
54 |
minCreationDate = cal.getTimeInMillis();
|
| 13668 |
manish.sha |
55 |
HttpGet get_new;
|
|
|
56 |
get_new = new HttpGet("https://seller.flipkart.com/");
|
|
|
57 |
get_new.addHeader("Host","seller.flipkart.com");
|
|
|
58 |
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");
|
|
|
59 |
get_new.addHeader("Connection","keep-alive");
|
|
|
60 |
|
|
|
61 |
HttpResponse response = client.execute(get_new);
|
|
|
62 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
63 |
String line = "";
|
|
|
64 |
while ((line = rd.readLine()) != null) {
|
|
|
65 |
System.out.println(line);
|
|
|
66 |
}
|
|
|
67 |
cookies = response.getFirstHeader("Set-Cookie") == null ? "" :
|
|
|
68 |
response.getFirstHeader("Set-Cookie").getValue();
|
|
|
69 |
|
|
|
70 |
System.out.println("Cookies Before Login "+ cookies);
|
|
|
71 |
|
| 9651 |
manish.sha |
72 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
73 |
nameValuePairs.add(new BasicNameValuePair("authName",
|
|
|
74 |
"flipkart"));
|
|
|
75 |
nameValuePairs.add(new BasicNameValuePair("username",
|
|
|
76 |
"flipkart-support@saholic.com"));
|
|
|
77 |
nameValuePairs.add(new BasicNameValuePair("password",
|
| 13184 |
manish.sha |
78 |
"bestmobiledeals2010"));
|
| 13668 |
manish.sha |
79 |
post.addHeader("Cookie",cookies);
|
| 12760 |
manish.sha |
80 |
post.addHeader("User-agent", "Mozilla/4.0");
|
|
|
81 |
post.addHeader("Referer", "seller.flipkart.com");
|
| 13668 |
manish.sha |
82 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
|
|
83 |
response = client.execute(post);
|
|
|
84 |
cookies = response.getFirstHeader("Set-Cookie") == null ? "" :
|
|
|
85 |
response.getFirstHeader("Set-Cookie").getValue();
|
|
|
86 |
System.out.println("Cookies After Login "+cookies);
|
| 9651 |
manish.sha |
87 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 13668 |
manish.sha |
88 |
line = "";
|
|
|
89 |
|
|
|
90 |
while ((line = rd.readLine()) != null) {
|
|
|
91 |
System.out.println(line);
|
|
|
92 |
}
|
| 12516 |
manish.sha |
93 |
|
| 9651 |
manish.sha |
94 |
long time;
|
|
|
95 |
int i=1;
|
|
|
96 |
time = System.currentTimeMillis();
|
| 12516 |
manish.sha |
97 |
|
|
|
98 |
outer:while(true){
|
| 12488 |
manish.sha |
99 |
get_new = new HttpGet("https://seller.flipkart.com/dashboard/som/shipped_order_items?status=delivered&page="+i+"&page_size=50&_="+time);
|
| 15763 |
manish.sha |
100 |
get_new.addHeader("Cookie",cookies+"; __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; __utma=19769839.1156779613.1390806906.1432813861.1435573112.27; __utmc=19769839; __utmz=19769839.1435573112.27.15.utmcsr=zimbrasmtp.com|utmccn=(referral)|utmcmd=referral|utmcct=/ch300-3.htm; s_ch_list=%5B%5B'Affiliates'%2C'1435573117633'%5D%5D; s_cc=true; s_ppv=0; s_sq=%5B%5BB%5D%5D; SN=2.VIB4C4C187B63B4436AAE42944FD9BE1C9.SI2B008083CC2145FFB103D6E76CDB343C.VS143557310149768094467.1435573140; VID=2.VIB4C4C187B63B4436AAE42944FD9BE1C9.1435573140.VS143557310149768094467; NSID=2.SI2B008083CC2145FFB103D6E76CDB343C.1435573140.VIB4C4C187B63B4436AAE42944FD9BE1C9; sellerId=m2z93iskuj81qiid; _ga=GA1.2.1156779613.1390806906; kvcd=1435740168445; km_vs=1; km_ai=m2z93iskuj81qiid; km_ni=m2z93iskuj81qiid; _gat=1; km_uq=; __utma=143439159.1156779613.1390806906.1435737045.1435740037.94; __utmb=143439159.9.9.1435740156534; __utmc=143439159; __utmz=143439159.1390806906.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _mkto_trk=id:021-QVV-957&token:_mch-flipkart.com-1434970574990-64308");
|
| 13668 |
manish.sha |
101 |
get_new.addHeader("Host","seller.flipkart.com");
|
|
|
102 |
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");
|
|
|
103 |
get_new.addHeader("Connection","keep-alive");
|
| 9651 |
manish.sha |
104 |
response = client.execute(get_new);
|
|
|
105 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
106 |
line = "";
|
| 12516 |
manish.sha |
107 |
|
| 12427 |
manish.sha |
108 |
JSONObject jsonDataObj = null;
|
|
|
109 |
line = rd.readLine();
|
| 12516 |
manish.sha |
110 |
|
| 12427 |
manish.sha |
111 |
JSONArray jsonObjArr = null;
|
| 12516 |
manish.sha |
112 |
|
| 12427 |
manish.sha |
113 |
if(line == null || line.isEmpty()){
|
| 12488 |
manish.sha |
114 |
if(i==120)
|
|
|
115 |
break;
|
|
|
116 |
i++;
|
|
|
117 |
continue;
|
| 9651 |
manish.sha |
118 |
}
|
| 12516 |
manish.sha |
119 |
|
| 12427 |
manish.sha |
120 |
jsonDataObj = new JSONObject(line);
|
|
|
121 |
jsonObjArr = new JSONArray(jsonDataObj.get("order_items").toString());
|
| 12516 |
manish.sha |
122 |
|
| 12427 |
manish.sha |
123 |
if(jsonObjArr==null || jsonObjArr.length()==0){
|
| 9651 |
manish.sha |
124 |
break;
|
|
|
125 |
}
|
| 12516 |
manish.sha |
126 |
|
| 12427 |
manish.sha |
127 |
if(jsonObjArr!=null && jsonObjArr.length()>0){
|
|
|
128 |
for(int k=0; k< jsonObjArr.length(); k++){
|
|
|
129 |
JSONObject jsonObj = null;
|
|
|
130 |
jsonObj = jsonObjArr.getJSONObject(k);
|
| 12516 |
manish.sha |
131 |
|
| 12427 |
manish.sha |
132 |
if(jsonObj!=null){
|
|
|
133 |
/*System.out.println("jsonObj..... "+ jsonObj);*/
|
|
|
134 |
if(minCreationDate > 0l && gotFlipkartDateFormat.parse(gotFlipkartDateFormat.format(minCreationDate)).getTime() <= gotFlipkartDateFormat.parse(jsonObj.get("created_date").toString()).getTime()){
|
|
|
135 |
List<String> delivered_dataList = new ArrayList<String>();
|
|
|
136 |
String externalId = jsonObj.get("external_id").toString();
|
|
|
137 |
String orderItemId = jsonObj.get("order_item_id").toString();
|
|
|
138 |
String modifiedDate = jsonObj.get("modified_date").toString();
|
|
|
139 |
delivered_dataList.add(externalId);
|
|
|
140 |
delivered_dataList.add(orderItemId);
|
| 12516 |
manish.sha |
141 |
|
| 12427 |
manish.sha |
142 |
delivered_dataList.add(ourDBDateFormat.format(gotFlipkartDateFormat.parse(modifiedDate).getTime()));
|
|
|
143 |
System.out.println("Flipkart Order Id... "+externalId + " ... Flipkart Sub Order Code... "+ orderItemId +" ... Delivery Date ... "+ ourDBDateFormat.format(gotFlipkartDateFormat.parse(modifiedDate).getTime()) + "....Created Date..... "+ jsonObj.get("created_date").toString());
|
|
|
144 |
deliveredOrderDataList.add(delivered_dataList);
|
|
|
145 |
}
|
| 12516 |
manish.sha |
146 |
else{
|
|
|
147 |
break outer;
|
|
|
148 |
}
|
| 12427 |
manish.sha |
149 |
}
|
|
|
150 |
}
|
|
|
151 |
}
|
| 12516 |
manish.sha |
152 |
|
| 9651 |
manish.sha |
153 |
i++;
|
|
|
154 |
}
|
| 12516 |
manish.sha |
155 |
|
| 12427 |
manish.sha |
156 |
System.out.println("deliveredOrderDataList size... "+deliveredOrderDataList.size());
|
| 9651 |
manish.sha |
157 |
if(deliveredOrderDataList!=null && deliveredOrderDataList.size()>0){
|
|
|
158 |
new TransactionClient().getClient().updateFlipkartOrdersStatus(deliveredOrderDataList);
|
|
|
159 |
}
|
| 12516 |
manish.sha |
160 |
|
| 9651 |
manish.sha |
161 |
} catch(Exception e){
|
|
|
162 |
e.printStackTrace();
|
| 12427 |
manish.sha |
163 |
mailer.sendSSLMessage(sendTo, "Error in Flipkart Order Status Recon", emailFromAddress, password, "<html><body><p>Please check log</p></body></html>");
|
| 9651 |
manish.sha |
164 |
}
|
|
|
165 |
}
|
|
|
166 |
}
|