Subversion Repositories SmartDukaan

Rev

Rev 15223 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15223 Rev 15599
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 UpdateSDPricingUsingPanel extends Thread{
38
public class UpdateSDPricingUsingPanel 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 UpdateSDPricingUsingPanel(Float price,String supc,Item item,Long timestamp){
60
	public UpdateSDPricingUsingPanel(Float price,String supc,Item item,Long timestamp){
50
		logger.info("Calling Update Snapdeal Price Constructor --" + " Price :" +price + " Supc :"+supc +" Item ID:" +item.getId());
61
		logger.info("Calling Update Snapdeal Price 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;
Line 60... Line 71...
60
		UpdateSDPricingUsingPanel updatePriceOnSnapdeal = new UpdateSDPricingUsingPanel(22200f,"1108903",item,System.currentTimeMillis());
71
		UpdateSDPricingUsingPanel updatePriceOnSnapdeal = new UpdateSDPricingUsingPanel(22200f,"1108903",item,System.currentTimeMillis());
61
		logger.info("Calling Thread to update price at snapdeal");
72
		logger.info("Calling Thread to update price at snapdeal");
62
		updatePriceOnSnapdeal.start();	
73
		updatePriceOnSnapdeal.start();	
63
 
74
 
64
	}
75
	}
65
	int updatePricing(Float price,String supc,Item item,Long timestamp) throws ClientProtocolException, IOException{
76
	int updatePricing(Float price,String supc,Item item,Long timestamp) throws Exception{
66
		logger.info("Calling Update Snapdeal Price Constructor --" + " Price :" +price + " Supc :"+supc +" Item ID:" +item.getId());
77
		logger.info("Calling Update Snapdeal Price Constructor --" + " Price :" +price + " Supc :"+supc +" Item ID:" +item.getId());
-
 
78
		SnapdealSessionCookie sdSessionCookie = new SnapdealSessionCookie();
-
 
79
		String cookies = "";
-
 
80
		JSONObject cookieObject = null;
67
		long priceVal = (long)price.floatValue();
81
		long priceVal = (long)price.floatValue();
68
		HttpPost post = new HttpPost("http://seller.snapdeal.com/pricing/update");
82
		HttpPost post = new HttpPost("http://seller.snapdeal.com/pricing/update");
-
 
83
		cookies = sdSessionCookie.getCookies();
-
 
84
		cookieObject = new JSONObject(cookies);
-
 
85
		for(String key:headers.keySet())
-
 
86
			post.addHeader(key, headers.get(key));
-
 
87
		post.addHeader("Cookie","SERVERID="+cookieObject.get("SERVERID")+";sfJSESSIONID="+cookieObject.get("sfJSESSIONID")+";");
69
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
88
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
70
		nameValuePairs.add(new BasicNameValuePair("changedField",
89
		nameValuePairs.add(new BasicNameValuePair("changedField",
71
                "sellingPrice"));
90
                "sellingPrice"));
72
		nameValuePairs.add(new BasicNameValuePair("changedValue",
91
		nameValuePairs.add(new BasicNameValuePair("changedValue",
73
				priceVal+""));
92
				priceVal+""));
Line 167... Line 186...
167
		logger.info("----Login Successful----" );
186
		logger.info("----Login Successful----" );
168
	}
187
	}
169
	public void run()
188
	public void run()
170
	{
189
	{
171
		try {
190
		try {
172
			this.handleLogin();
-
 
173
			this.updatePricing(this.price,this.supc,this.item,timestamp);
191
			this.updatePricing(this.price,this.supc,this.item,timestamp);
174
			boolean retry =true;
192
			boolean retry =true;
-
 
193
			SnapdealSessionCookie sdSessionCookie = new SnapdealSessionCookie();
-
 
194
			String cookies = "";
-
 
195
			JSONObject cookieObject = null;
175
			while(retry){
196
			while(retry){
176
				Thread.sleep(2*60*1000);
197
				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");
198
				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");
-
 
199
				cookies = sdSessionCookie.getCookies();
-
 
200
				cookieObject = new JSONObject(cookies);
-
 
201
				for(String key:headers.keySet())
-
 
202
					get.addHeader(key, headers.get(key));
-
 
203
				get.addHeader("Cookie","SERVERID="+cookieObject.get("SERVERID")+";sfJSESSIONID="+cookieObject.get("sfJSESSIONID")+";");
178
				HttpResponse response = httpClient.execute(get);
204
				HttpResponse response = httpClient.execute(get);
179
				BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
205
				BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
180
				String line = "";
206
				String line = "";
181
				while ((line = rd.readLine()) != null) {
207
				while ((line = rd.readLine()) != null) {
182
					logger.info(line);
208
					logger.info(line);