Subversion Repositories SmartDukaan

Rev

Rev 15022 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15022 Rev 15600
Line 2... Line 2...
2
 
2
 
3
import in.shop2020.model.v1.catalog.CatalogService.Client;
3
import in.shop2020.model.v1.catalog.CatalogService.Client;
4
import in.shop2020.model.v1.catalog.CatalogServiceException;
4
import in.shop2020.model.v1.catalog.CatalogServiceException;
5
import in.shop2020.model.v1.catalog.Item;
5
import in.shop2020.model.v1.catalog.Item;
6
import in.shop2020.model.v1.order.OrderSource;
6
import in.shop2020.model.v1.order.OrderSource;
-
 
7
import in.shop2020.serving.services.SnapdealSessionCookie;
7
import in.shop2020.thrift.clients.CatalogClient;
8
import in.shop2020.thrift.clients.CatalogClient;
8
import in.shop2020.utils.GmailUtils;
9
import in.shop2020.utils.GmailUtils;
9
 
10
 
10
import java.io.BufferedReader;
11
import java.io.BufferedReader;
11
import java.io.File;
12
import java.io.File;
12
import java.io.IOException;
13
import java.io.IOException;
13
import java.io.InputStreamReader;
14
import java.io.InputStreamReader;
14
import java.util.ArrayList;
15
import java.util.ArrayList;
-
 
16
import java.util.HashMap;
15
import java.util.List;
17
import java.util.List;
-
 
18
import java.util.Map;
16
 
19
 
17
import javax.mail.MessagingException;
20
import javax.mail.MessagingException;
18
 
21
 
19
import org.apache.http.HttpResponse;
22
import org.apache.http.HttpResponse;
20
import org.apache.http.NameValuePair;
23
import org.apache.http.NameValuePair;
Line 26... Line 29...
26
import org.apache.http.impl.client.DefaultHttpClient;
29
import org.apache.http.impl.client.DefaultHttpClient;
27
import org.apache.http.impl.conn.PoolingClientConnectionManager;
30
import org.apache.http.impl.conn.PoolingClientConnectionManager;
28
import org.apache.http.message.BasicNameValuePair;
31
import org.apache.http.message.BasicNameValuePair;
29
import org.apache.thrift.TException;
32
import org.apache.thrift.TException;
30
import org.apache.thrift.transport.TTransportException;
33
import org.apache.thrift.transport.TTransportException;
-
 
34
import org.json.JSONObject;
31
import org.slf4j.Logger;
35
import org.slf4j.Logger;
32
import org.slf4j.LoggerFactory;
36
import org.slf4j.LoggerFactory;
33
 
37
 
34
public class UpdateSnapdealVoiPricingUsingPanel extends Thread{
38
public class UpdateSnapdealVoiPricingUsingPanel extends Thread{
35
	static ClientConnectionManager connManager = new PoolingClientConnectionManager();
39
	static ClientConnectionManager connManager = new PoolingClientConnectionManager();
Line 44... Line 48...
44
	public String[] sendTo = new String[]{ "sandeep.sachdeva@shop2020.in", "manish.sharma@shop2020.in", "rajneesh.arora@shop2020.in",
48
	public String[] sendTo = new String[]{ "sandeep.sachdeva@shop2020.in", "manish.sharma@shop2020.in", "rajneesh.arora@shop2020.in",
45
			"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
49
			"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
46
			"yukti.jain@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","kshitij.sood@shop2020.in"};
50
			"yukti.jain@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","kshitij.sood@shop2020.in"};
47
	public String emailFromAddress = "build@shop2020.in";
51
	public String emailFromAddress = "build@shop2020.in";
48
	public String password = "cafe@nes";
52
	public String password = "cafe@nes";
-
 
53
	private static Map<String, String> headers = new HashMap<String, String>();
-
 
54
	static {
-
 
55
		headers.put("User-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11");
-
 
56
		headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
-
 
57
		headers.put("Accept-Language", "en-US,en;q=0.8");
-
 
58
		headers.put("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
-
 
59
	}
49
	public UpdateSnapdealVoiPricingUsingPanel(Float price,String supc,Item item,Long timestamp){
60
	public UpdateSnapdealVoiPricingUsingPanel(Float price,String supc,Item item,Long timestamp){
50
		logger.info("Calling Update Snapdeal Price VOI Constructor --" + " Price :" +price + " Supc :"+supc +" Item ID:" +item.getId());
61
		logger.info("Calling Update Snapdeal Price VOI Constructor --" + " Price :" +price + " Supc :"+supc +" Item ID:" +item.getId());
51
		this.price = price;
62
		this.price = price;
52
		this.supc = supc;
63
		this.supc = supc;
53
		this.item = item;
64
		this.item = item;
54
		this.timestamp = timestamp; 
65
		this.timestamp = timestamp; 
55
	}
66
	}
-
 
67
	
56
	public UpdateSnapdealVoiPricingUsingPanel() {
68
	public UpdateSnapdealVoiPricingUsingPanel() {
57
	}
69
	}
58
	public static void main(String... args) throws ClientProtocolException, IOException, TTransportException, CatalogServiceException, TException{
70
	public static void main(String... args) throws ClientProtocolException, IOException, TTransportException, CatalogServiceException, TException{
59
		Item item = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient().getItem(2231);
71
		Item item = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient().getItem(2231);
60
		UpdateSnapdealVoiPricingUsingPanel updatePriceOnSnapdeal = new UpdateSnapdealVoiPricingUsingPanel(22200f,"1108903",item,System.currentTimeMillis());
72
		UpdateSnapdealVoiPricingUsingPanel updatePriceOnSnapdeal = new UpdateSnapdealVoiPricingUsingPanel(22200f,"1108903",item,System.currentTimeMillis());
61
		logger.info("Calling Thread to update price at snapdeal");
73
		logger.info("Calling Thread to update price at snapdeal");
62
		updatePriceOnSnapdeal.start();	
74
		updatePriceOnSnapdeal.start();	
63
 
75
 
64
	}
76
	}
65
	int updatePricing(Float price,String supc,Item item,Long timestamp) throws ClientProtocolException, IOException{
77
	int updatePricing(Float price,String supc,Item item,Long timestamp) throws Exception{
66
		logger.info("Calling Update Snapdeal VOI Price Constructor --" + " Price :" +price + " supc :"+supc +" Item ID:" +item.getId());
78
		logger.info("Calling Update Snapdeal VOI Price Constructor --" + " Price :" +price + " supc :"+supc +" Item ID:" +item.getId());
-
 
79
		SnapdealSessionCookie sdSessionCookie = new SnapdealSessionCookie();
-
 
80
		String cookies = "";
-
 
81
		JSONObject cookieObject = null;
67
		long priceVal = (long)price.floatValue();
82
		long priceVal = (long)price.floatValue();
68
		HttpPost post = new HttpPost("http://seller.snapdeal.com/pricing/update");
83
		HttpPost post = new HttpPost("http://seller.snapdeal.com/pricing/update");
-
 
84
		cookies = sdSessionCookie.getVoiCookies();
-
 
85
		cookieObject = new JSONObject(cookies);
-
 
86
		for(String key:headers.keySet())
-
 
87
			post.addHeader(key, headers.get(key));
-
 
88
		post.addHeader("Cookie","SERVERID="+cookieObject.get("SERVERID")+";sfJSESSIONID="+cookieObject.get("sfJSESSIONID")+";");
69
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
89
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
70
		nameValuePairs.add(new BasicNameValuePair("changedField",
90
		nameValuePairs.add(new BasicNameValuePair("changedField",
71
                "sellingPrice"));
91
                "sellingPrice"));
72
		nameValuePairs.add(new BasicNameValuePair("changedValue",
92
		nameValuePairs.add(new BasicNameValuePair("changedValue",
73
				priceVal+""));
93
				priceVal+""));
Line 82... Line 102...
82
			System.out.println(line);
102
			System.out.println(line);
83
		}
103
		}
84
		return 1;
104
		return 1;
85
	}
105
	}
86
 
106
 
87
	public void handleLogin() throws ClientProtocolException, IOException{
-
 
88
		logger.info("----Inside Handle Login VOI ----" );
-
 
89
		HttpGet get = new HttpGet("http://selleraccounts.snapdeal.com/login?service=http%3A%2F%2Fseller.snapdeal.com%2Fj_spring_cas_security_check");
-
 
90
		HttpResponse response = null;
-
 
91
		boolean retry = true;
-
 
92
		while(retry){
-
 
93
			try {
-
 
94
				response = httpClient.execute(get);
-
 
95
				retry = false;
-
 
96
			} catch (ClientProtocolException e) {
-
 
97
				e.printStackTrace();
-
 
98
				logger.error("Exception ",e);
-
 
99
			} catch (IOException e) {
-
 
100
				e.printStackTrace();
-
 
101
				logger.info("Exception " + e);
-
 
102
			}
-
 
103
		}
-
 
104
		BufferedReader rd = null;
-
 
105
		try {
-
 
106
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
-
 
107
		} catch (IllegalStateException e1) {
-
 
108
			e1.printStackTrace();
-
 
109
		} catch (IOException e1) {
-
 
110
			e1.printStackTrace();
-
 
111
		}
-
 
112
		String line = "";
-
 
113
		StringBuffer sb = new StringBuffer();
-
 
114
		try {
-
 
115
			while ((line = rd.readLine()) != null) {
-
 
116
				sb.append(line);
-
 
117
			}
-
 
118
		} catch (IOException e) {
-
 
119
			e.printStackTrace();
-
 
120
		}
-
 
121
		int i= sb.toString().indexOf("name=\"lt\" value=");
-
 
122
		char[] charArray = sb.toString().toCharArray();
-
 
123
		String lt = "";
-
 
124
		int j=0;
-
 
125
		for(j=i+16;j<=charArray.length;j++){
-
 
126
 
-
 
127
			if(charArray[j]==' '){
-
 
128
				break;
-
 
129
			}
-
 
130
		}
-
 
131
		lt = sb.substring(i+17,j-1);
-
 
132
		System.out.println("LT VALUE " + lt);
-
 
133
		i= sb.toString().indexOf("name=\"execution\" value=");
-
 
134
		charArray = sb.toString().toCharArray();
-
 
135
		String ex = "";
-
 
136
		j=0;
-
 
137
		for(j=i+24;j<=charArray.length;j++){
-
 
138
			if(charArray[j]==' '){
-
 
139
				break;
-
 
140
			}
-
 
141
		}
-
 
142
		ex = sb.substring(i+24,j-1);
-
 
143
		System.out.println("EXECUTION VALUE " + ex);
-
 
144
		HttpPost post = new HttpPost("http://selleraccounts.snapdeal.com/login?service=http%3A%2F%2Fseller.snapdeal.com%2Fj_spring_cas_security_check");
-
 
145
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
-
 
146
		nameValuePairs.add(new BasicNameValuePair("username",
-
 
147
		"spiceonlineretailvoi@gmail.com"));
-
 
148
		nameValuePairs.add(new BasicNameValuePair("password",
-
 
149
		"snapdealsaholic"));
-
 
150
		nameValuePairs.add(new BasicNameValuePair("_eventId","submit"));
-
 
151
		nameValuePairs.add(new BasicNameValuePair("execution",ex));
-
 
152
		nameValuePairs.add(new BasicNameValuePair("lt",lt));
-
 
153
		nameValuePairs.add(new BasicNameValuePair("submit","LOGIN"));
-
 
154
		post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
-
 
155
		response = httpClient.execute(post);
-
 
156
		rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
-
 
157
		line = "";
-
 
158
		while ((line = rd.readLine()) != null) {
-
 
159
			System.out.println(line);
-
 
160
		}
-
 
161
		get = new HttpGet("http://seller.snapdeal.com/pricing");
-
 
162
		response = httpClient.execute(get);
-
 
163
		rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
-
 
164
		while ((line = rd.readLine()) != null) {
-
 
165
			//System.out.println(line);
-
 
166
		}
-
 
167
		logger.info("----Login Successful----" );
-
 
168
	}
-
 
169
	public void run()
107
	public void run()
170
	{
108
	{
171
		try {
109
		try {
172
			this.handleLogin();
-
 
173
			this.updatePricing(this.price,this.supc,this.item,timestamp);
110
			this.updatePricing(this.price,this.supc,this.item,timestamp);
174
			boolean retry =true;
111
			boolean retry =true;
-
 
112
			SnapdealSessionCookie sdSessionCookie = new SnapdealSessionCookie();
-
 
113
			String cookies = "";
-
 
114
			JSONObject cookieObject = null;
175
			while(retry){
115
			while(retry){
176
				Thread.sleep(2*60*1000);
116
				Thread.sleep(2*60*1000);
177
				HttpGet get = new HttpGet("http://seller.snapdeal.com/pricing/search?searchType=SUPC&searchValue="+this.supc+"&gridType=normal&_search=false&nd="+System.currentTimeMillis()+"&rows=30&page=1&sidx=&sord=asc");
117
				HttpGet get = new HttpGet("http://seller.snapdeal.com/pricing/search?searchType=SUPC&searchValue="+this.supc+"&gridType=normal&_search=false&nd="+System.currentTimeMillis()+"&rows=30&page=1&sidx=&sord=asc");
-
 
118
				cookies = sdSessionCookie.getVoiCookies();
-
 
119
				cookieObject = new JSONObject(cookies);
-
 
120
				for(String key:headers.keySet())
-
 
121
					get.addHeader(key, headers.get(key));
-
 
122
				get.addHeader("Cookie","SERVERID="+cookieObject.get("SERVERID")+";sfJSESSIONID="+cookieObject.get("sfJSESSIONID")+";");
178
				HttpResponse response = httpClient.execute(get);
123
				HttpResponse response = httpClient.execute(get);
179
				BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
124
				BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
180
				String line = "";
125
				String line = "";
181
				while ((line = rd.readLine()) != null) {
126
				while ((line = rd.readLine()) != null) {
182
					logger.info(line);
127
					logger.info(line);