Rev 12760 | Rev 13167 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.serving.services;import in.shop2020.model.v1.order.OrderSource;import in.shop2020.serving.model.Order;import in.shop2020.serving.model.OrderItems;import in.shop2020.thrift.clients.TransactionClient;import in.shop2020.utils.GmailUtils;import java.io.BufferedReader;import java.io.InputStreamReader;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Calendar;import java.util.Date;import java.util.List;import javax.mail.MessagingException;import org.apache.http.HttpResponse;import org.apache.http.NameValuePair;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.impl.client.DefaultHttpClient;import org.apache.http.message.BasicNameValuePair;import org.json.JSONArray;import org.json.JSONObject;import com.google.gson.Gson;public class FlipkartOrderStatusReconciliation{static String emailFromAddress;static String password;static GmailUtils mailer;static String sendTo[];static {emailFromAddress = "build-staging@shop2020.in";password = "shop2020";mailer = new GmailUtils();sendTo = new String[] { "kshitij.sood@shop2020.in", "manish.sharma@shop2020.in", "amit.gupta@shop2020.in" };}public static void main(String[] args) throws MessagingException {HttpClient client = new DefaultHttpClient();HttpPost post = new HttpPost("https://seller.flipkart.com/login");BufferedReader rd= null;List<List<String>> deliveredOrderDataList = new ArrayList<List<String>>();SimpleDateFormat gotFlipkartDateFormat = new SimpleDateFormat("MMM dd, yyyy");//SimpleDateFormat createDateFormatter = new SimpleDateFormat("MMM dd, yyyy hh:mm aaa");SimpleDateFormat ourDBDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");long minCreationDate = 0l;try {/*minCreationDate = 1386432631000l;new TransactionClient().getClient().getMinCreatedTimeStampUndeliveredOrdersForSource(OrderSource.FLIPKART.getValue());*/Calendar cal = Calendar.getInstance();cal.add(Calendar.DAY_OF_MONTH, -30);minCreationDate = cal.getTimeInMillis();List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();nameValuePairs.add(new BasicNameValuePair("authName","flipkart"));nameValuePairs.add(new BasicNameValuePair("username","flipkart-support@saholic.com"));nameValuePairs.add(new BasicNameValuePair("password","076c27ee24d7596b06608a8ed2559f87"));post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));post.addHeader("Cookie","T=TI138130450866706710769873257251497444628820234222703981199700765991; __gads=ID=dfe0374cf04d1576:T=1381304511:S=ALNI_Ma2TpDrlF9_amkoqp3MOYJBaFAOUg; km_lv=x; __sonar=6631097455123118581; __isReg=true; connect.sid=s%3AWwlGdtrLzj38cMjvZPI6ib5J.YUhinXC189untGw58i2CE9k7BGgKQJs9L%2BVIYPIW9Ok; is_login=true; sellerId=m2z93iskuj81qiid; __utma=143439159.1156779613.1390806906.1412575623.1412581840.30; __utmc=143439159; __utmz=143439159.1390806906.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); pincode=110001; S=d1t17uBGP%2FSlPrRt2tpUnAFVMIP3X6vbS8VVSIjMrWMoY2HMx3d4ZaG7UZNIW4uhS2vEDllnTlWndGOX15%2FPyLnmgnw%3D%3D; __utma=19769839.1733153395.1408690721.1412603997.1412663006.15; __utmb=19769839.3.10.1412663006; __utmc=19769839; __utmz=19769839.1409028689.3.2.utmcsr=savemoneyindia.com|utmccn=(referral)|utmcmd=referral|utmcct=/; s_cc=true; gpv_pn=Homepage; gpv_pn_t=no%20value; s_sq=%5B%5BB%5D%5D; s_ppv=14; SN=2.VI4876EB87B4D54359BF5BDC59495E6FAC.SIC5C9F56B37DA4EE59E2226123257E3B6.VS141266300525440480188.1412663034; VID=2.VI4876EB87B4D54359BF5BDC59495E6FAC.1412663034.VS141266300525440480188; NSID=2.SIC5C9F56B37DA4EE59E2226123257E3B6.1412663034.VI4876EB87B4D54359BF5BDC59495E6FAC; _ga=GA1.2.1156779613.1390806906; kvcd=1412663072574; km_ai=m2z93iskuj81qiid; km_ni=m2z93iskuj81qiid; km_vs=1; km_uq=");post.addHeader("User-agent", "Mozilla/4.0");post.addHeader("Referer", "seller.flipkart.com");HttpResponse response = client.execute(post);rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));String line = "";Gson gson;List<Order> orders = new ArrayList<Order>();OrderItems new_orders;HttpGet get_new;long time;int i=1;while ((line = rd.readLine()) != null) {System.out.println(line);}time = System.currentTimeMillis();outer:while(true){get_new = new HttpGet("https://seller.flipkart.com/dashboard/som/shipped_order_items?status=delivered&page="+i+"&page_size=50&_="+time);//get_new.addHeader("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=");get_new.addHeader("Cookie","T=TI138130450866706710769873257251497444628820234222703981199700765991; __gads=ID=dfe0374cf04d1576:T=1381304511:S=ALNI_Ma2TpDrlF9_amkoqp3MOYJBaFAOUg; km_lv=x; __sonar=6631097455123118581; __isReg=true; connect.sid=s%3AWwlGdtrLzj38cMjvZPI6ib5J.YUhinXC189untGw58i2CE9k7BGgKQJs9L%2BVIYPIW9Ok; is_login=true; sellerId=m2z93iskuj81qiid; __utma=143439159.1156779613.1390806906.1412575623.1412581840.30; __utmc=143439159; __utmz=143439159.1390806906.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); pincode=110001; S=d1t17uBGP%2FSlPrRt2tpUnAFVMIP3X6vbS8VVSIjMrWMoY2HMx3d4ZaG7UZNIW4uhS2vEDllnTlWndGOX15%2FPyLnmgnw%3D%3D; __utma=19769839.1733153395.1408690721.1412603997.1412663006.15; __utmb=19769839.3.10.1412663006; __utmc=19769839; __utmz=19769839.1409028689.3.2.utmcsr=savemoneyindia.com|utmccn=(referral)|utmcmd=referral|utmcct=/; s_cc=true; gpv_pn=Homepage; gpv_pn_t=no%20value; s_sq=%5B%5BB%5D%5D; s_ppv=14; SN=2.VI4876EB87B4D54359BF5BDC59495E6FAC.SIC5C9F56B37DA4EE59E2226123257E3B6.VS141266300525440480188.1412663034; VID=2.VI4876EB87B4D54359BF5BDC59495E6FAC.1412663034.VS141266300525440480188; NSID=2.SIC5C9F56B37DA4EE59E2226123257E3B6.1412663034.VI4876EB87B4D54359BF5BDC59495E6FAC; _ga=GA1.2.1156779613.1390806906; kvcd=1412663072574; km_ai=m2z93iskuj81qiid; km_ni=m2z93iskuj81qiid; km_vs=1; km_uq=");response = client.execute(get_new);rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));line = "";gson = new Gson();JSONObject jsonDataObj = null;line = rd.readLine();JSONArray jsonObjArr = null;if(line == null || line.isEmpty()){if(i==120)break;i++;continue;}jsonDataObj = new JSONObject(line);jsonObjArr = new JSONArray(jsonDataObj.get("order_items").toString());if(jsonObjArr==null || jsonObjArr.length()==0){break;}if(jsonObjArr!=null && jsonObjArr.length()>0){for(int k=0; k< jsonObjArr.length(); k++){JSONObject jsonObj = null;jsonObj = jsonObjArr.getJSONObject(k);if(jsonObj!=null){/*System.out.println("jsonObj..... "+ jsonObj);*/if(minCreationDate > 0l && gotFlipkartDateFormat.parse(gotFlipkartDateFormat.format(minCreationDate)).getTime() <= gotFlipkartDateFormat.parse(jsonObj.get("created_date").toString()).getTime()){List<String> delivered_dataList = new ArrayList<String>();String externalId = jsonObj.get("external_id").toString();String orderItemId = jsonObj.get("order_item_id").toString();String modifiedDate = jsonObj.get("modified_date").toString();delivered_dataList.add(externalId);delivered_dataList.add(orderItemId);delivered_dataList.add(ourDBDateFormat.format(gotFlipkartDateFormat.parse(modifiedDate).getTime()));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());deliveredOrderDataList.add(delivered_dataList);}else{break outer;}}}}i++;}System.out.println("deliveredOrderDataList size... "+deliveredOrderDataList.size());if(deliveredOrderDataList!=null && deliveredOrderDataList.size()>0){new TransactionClient().getClient().updateFlipkartOrdersStatus(deliveredOrderDataList);}} catch(Exception e){e.printStackTrace();mailer.sendSSLMessage(sendTo, "Error in Flipkart Order Status Recon", emailFromAddress, password, "<html><body><p>Please check log</p></body></html>");}}}