| 10543 |
vikram.rag |
1 |
package in.shop2020;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
|
|
4 |
import in.shop2020.model.v1.catalog.FlipkartItem;
|
|
|
5 |
import in.shop2020.model.v1.inventory.FlipkartStockAtEOD;
|
|
|
6 |
import in.shop2020.model.v1.inventory.SnapdealStockAtEOD;
|
|
|
7 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
8 |
import in.shop2020.thrift.clients.InventoryClient;
|
|
|
9 |
import in.shop2020.utils.GmailUtils;
|
|
|
10 |
import java.io.BufferedReader;
|
|
|
11 |
import java.io.File;
|
|
|
12 |
import java.io.IOException;
|
|
|
13 |
import java.io.InputStreamReader;
|
|
|
14 |
import java.io.UnsupportedEncodingException;
|
|
|
15 |
import java.util.ArrayList;
|
|
|
16 |
import java.util.HashMap;
|
|
|
17 |
import java.util.List;
|
|
|
18 |
import java.util.Map;
|
|
|
19 |
import java.util.Map.Entry;
|
|
|
20 |
import in.shop2020.WebClientWrapper;
|
|
|
21 |
import javax.mail.MessagingException;
|
|
|
22 |
import inventory.FlipkartJSONreponse;
|
|
|
23 |
import org.apache.http.HttpResponse;
|
|
|
24 |
import org.apache.http.NameValuePair;
|
|
|
25 |
import org.apache.http.auth.AuthScope;
|
|
|
26 |
import org.apache.http.auth.UsernamePasswordCredentials;
|
|
|
27 |
import org.apache.http.client.ClientProtocolException;
|
|
|
28 |
import org.apache.http.client.HttpClient;
|
|
|
29 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
30 |
import org.apache.http.client.methods.HttpGet;
|
|
|
31 |
import org.apache.http.client.methods.HttpPost;
|
|
|
32 |
import org.apache.http.entity.StringEntity;
|
|
|
33 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
34 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
35 |
import org.apache.thrift.TException;
|
|
|
36 |
import org.apache.thrift.transport.TTransportException;
|
|
|
37 |
|
|
|
38 |
import com.google.gson.Gson;
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
public class FlipkartInventoryAtEOD {
|
|
|
43 |
private static List<FlipkartItem> flipkartItems;
|
|
|
44 |
static java.text.SimpleDateFormat sdf;
|
|
|
45 |
static String emailFromAddress;
|
|
|
46 |
static String password;
|
|
|
47 |
static GmailUtils mailer;
|
|
|
48 |
static String sendTo[];
|
|
|
49 |
static
|
|
|
50 |
{
|
|
|
51 |
sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
|
|
|
52 |
emailFromAddress = "build@shop2020.in";
|
|
|
53 |
password = "cafe@nes";
|
|
|
54 |
mailer = new GmailUtils();
|
|
|
55 |
sendTo = new String[]{"vikram.raghav@shop2020.in"};
|
|
|
56 |
/* sendTo = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
|
|
|
57 |
"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
|
|
|
58 |
"yukti.jain@shop2020.in","manoj.pal@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","amar.kumar@shop2020.in"};
|
|
|
59 |
*/ List<String> flipkartorderids = null;
|
|
|
60 |
Client catalogServiceClient = null;
|
|
|
61 |
try {
|
|
|
62 |
catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
|
|
63 |
} catch (TTransportException e) {
|
|
|
64 |
e.printStackTrace();
|
|
|
65 |
}
|
|
|
66 |
try {
|
|
|
67 |
flipkartItems = catalogServiceClient.getAllFlipkartItems();
|
|
|
68 |
} catch (TException e) {
|
|
|
69 |
e.printStackTrace();
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
public static void main(String[] args) throws ClientProtocolException, TException{
|
|
|
74 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
|
75 |
httpclient = (DefaultHttpClient) WebClientWrapper.wrapClient(httpclient);
|
|
|
76 |
//httpclient.getCredentialsProvider().setCredentials(
|
|
|
77 |
// new AuthScope("sandbox-api.flipkart.net", 443),
|
|
|
78 |
// new UsernamePasswordCredentials("og3yg5994bxbxxc1", "8a137068-417c-4e4f-ae95-9295ab938d88"));/// Test Server Access Keys
|
|
|
79 |
httpclient.getCredentialsProvider().setCredentials(
|
|
|
80 |
new AuthScope("api.flipkart.net", 443),
|
|
|
81 |
new UsernamePasswordCredentials("m2z93iskuj81qiid","0c7ab6a5-98c0-4cdc-8be3-72c591e0add4")); //Prod Server Access Keys
|
|
|
82 |
HttpGet httpget;
|
|
|
83 |
BufferedReader rd = null;
|
|
|
84 |
Gson gson = new Gson();
|
|
|
85 |
List<FlipkartStockAtEOD> allflipkartstock = new ArrayList<FlipkartStockAtEOD>();
|
|
|
86 |
FlipkartStockAtEOD stockItem;
|
|
|
87 |
Long time = System.currentTimeMillis();
|
|
|
88 |
for(FlipkartItem flipkartItem:flipkartItems){
|
|
|
89 |
httpget = new HttpGet("https://api.flipkart.net/sellers/skus/"+flipkartItem.getSkuAtFlipkart()+"/listings"); // PROD
|
|
|
90 |
HttpResponse response = null;
|
|
|
91 |
try {
|
|
|
92 |
response = httpclient.execute(httpget);
|
|
|
93 |
} catch (IOException e) {
|
|
|
94 |
e.printStackTrace();
|
|
|
95 |
}
|
|
|
96 |
try {
|
|
|
97 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
98 |
} catch (Exception e) {
|
|
|
99 |
e.printStackTrace();
|
|
|
100 |
}
|
|
|
101 |
/*try {
|
|
|
102 |
System.out.println("Response :" + rd.readLine());
|
|
|
103 |
} catch (IOException e) {
|
|
|
104 |
e.printStackTrace();
|
|
|
105 |
}*/
|
|
|
106 |
FlipkartJSONreponse flipkartJSONreponse = (FlipkartJSONreponse) gson.fromJson(rd, FlipkartJSONreponse.class);
|
|
|
107 |
if(flipkartJSONreponse!=null){
|
|
|
108 |
stockItem = new FlipkartStockAtEOD();
|
|
|
109 |
System.out.println("Item ID :" + flipkartItem.getSkuAtFlipkart());
|
|
|
110 |
stockItem.setItem_id(flipkartItem.getItem_id());
|
|
|
111 |
System.out.println("Item ID :" + flipkartItem.getItem_id());
|
|
|
112 |
System.out.println("Listing ID :" + flipkartJSONreponse.getListingId());
|
|
|
113 |
System.out.println("SKU at Flipkart :" + flipkartJSONreponse.getSkuId());
|
|
|
114 |
System.out.println("Stock Count :" + flipkartJSONreponse.getAttributes().getStock_count());
|
|
|
115 |
stockItem.setAvailability(Long.valueOf(flipkartJSONreponse.getAttributes().getStock_count()));
|
|
|
116 |
stockItem.setDate(time);
|
|
|
117 |
allflipkartstock.add(stockItem);
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
try{
|
|
|
121 |
new InventoryClient().getClient().updateFlipkartStockAtEOD(allflipkartstock);
|
|
|
122 |
}
|
|
|
123 |
catch(Exception e){
|
|
|
124 |
new InventoryClient().getClient().updateFlipkartStockAtEOD(allflipkartstock);
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
}
|