Subversion Repositories SmartDukaan

Rev

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

Rev 13858 Rev 14780
Line 37... Line 37...
37
	//private static DefaultHttpClient httpClient = new DefaultHttpClient();
37
	//private static DefaultHttpClient httpClient = new DefaultHttpClient();
38
	private Float price;
38
	private Float price;
39
	private String supc;
39
	private String supc;
40
	private Item item;
40
	private Item item;
41
	private Long timestamp;
41
	private Long timestamp;
-
 
42
	public boolean voiUpdation;
42
	//public String[] sendTo = new String[]{"vikram.raghav@shop2020.in"};
43
	//public String[] sendTo = new String[]{"vikram.raghav@shop2020.in"};
43
	private static Logger logger = LoggerFactory.getLogger(UpdateSDPricingUsingPanel.class);
44
	private static Logger logger = LoggerFactory.getLogger(UpdateSDPricingUsingPanel.class);
44
	public String[] sendTo = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
45
	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",
46
			"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"};
47
			"yukti.jain@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","kshitij.sood@shop2020.in"};
47
	public String emailFromAddress = "build@shop2020.in";
48
	public String emailFromAddress = "build@shop2020.in";
48
	public String password = "cafe@nes";
49
	public String password = "cafe@nes";
49
	public UpdateSDPricingUsingPanel(Float price,String supc,Item item,Long timestamp){
50
	public UpdateSDPricingUsingPanel(Float price,String supc,Item item,Long timestamp){
Line 53... Line 54...
53
		this.item = item;
54
		this.item = item;
54
		this.timestamp = timestamp; 
55
		this.timestamp = timestamp; 
55
	}
56
	}
56
	public UpdateSDPricingUsingPanel() {
57
	public UpdateSDPricingUsingPanel() {
57
	}
58
	}
-
 
59
	
-
 
60
	public UpdateSDPricingUsingPanel(Float price,String supc,Item item,Long timestamp, boolean voiUpdation){
-
 
61
		logger.info("Calling Update Snapdeal Price Constructor --" + " Price :" +price + " Supc :"+supc +" Item ID:" +item.getId()+" VOI Updation: "+voiUpdation);
-
 
62
		this.price = price;
-
 
63
		this.supc = supc;
-
 
64
		this.item = item;
-
 
65
		this.timestamp = timestamp; 
-
 
66
		this.voiUpdation = voiUpdation;
-
 
67
	}
58
	public static void main(String... args) throws ClientProtocolException, IOException, TTransportException, CatalogServiceException, TException{
68
	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);
69
		Item item = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient().getItem(2231);
60
		UpdateSDPricingUsingPanel updatePriceOnSnapdeal = new UpdateSDPricingUsingPanel(22200f,"1108903",item,System.currentTimeMillis());
70
		UpdateSDPricingUsingPanel updatePriceOnSnapdeal = new UpdateSDPricingUsingPanel(22200f,"1108903",item,System.currentTimeMillis());
61
		logger.info("Calling Thread to update price at snapdeal");
71
		logger.info("Calling Thread to update price at snapdeal");
62
		updatePriceOnSnapdeal.start();	
72
		updatePriceOnSnapdeal.start();
63
 
-
 
64
	}
73
	}
65
	int updatePricing(Float price,String supc,Item item,Long timestamp) throws ClientProtocolException, IOException{
74
	int updatePricing(Float price,String supc,Item item,Long timestamp) throws ClientProtocolException, IOException{
66
		logger.info("Calling Update Snapdeal Price Constructor --" + " Price :" +price + " Supc :"+supc +" Item ID:" +item.getId());
75
		logger.info("Calling Update Snapdeal Price Constructor --" + " Price :" +price + " Supc :"+supc +" Item ID:" +item.getId());
67
		long priceVal = (long)price.floatValue();
76
		long priceVal = (long)price.floatValue();
68
		HttpPost post = new HttpPost("http://seller.snapdeal.com/pricing/update");
77
		HttpPost post = new HttpPost("http://seller.snapdeal.com/pricing/update");
Line 164... Line 173...
164
		while ((line = rd.readLine()) != null) {
173
		while ((line = rd.readLine()) != null) {
165
			//System.out.println(line);
174
			//System.out.println(line);
166
		}
175
		}
167
		logger.info("----Login Successful----" );
176
		logger.info("----Login Successful----" );
168
	}
177
	}
-
 
178
	
-
 
179
	public void handleVoiLogin() throws ClientProtocolException, IOException{
-
 
180
		logger.info("----Inside Handle Voi Login ----" );
-
 
181
		HttpGet get = new HttpGet("http://selleraccounts.snapdeal.com/login?service=http%3A%2F%2Fseller.snapdeal.com%2Fj_spring_cas_security_check");
-
 
182
		HttpResponse response = null;
-
 
183
		boolean retry = true;
-
 
184
		while(retry){
-
 
185
			try {
-
 
186
				response = httpClient.execute(get);
-
 
187
				retry = false;
-
 
188
			} catch (ClientProtocolException e) {
-
 
189
				e.printStackTrace();
-
 
190
				logger.error("Exception ",e);
-
 
191
			} catch (IOException e) {
-
 
192
				e.printStackTrace();
-
 
193
				logger.info("Exception " + e);
-
 
194
			}
-
 
195
		}
-
 
196
		BufferedReader rd = null;
-
 
197
		try {
-
 
198
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
-
 
199
		} catch (IllegalStateException e1) {
-
 
200
			e1.printStackTrace();
-
 
201
		} catch (IOException e1) {
-
 
202
			e1.printStackTrace();
-
 
203
		}
-
 
204
		String line = "";
-
 
205
		StringBuffer sb = new StringBuffer();
-
 
206
		try {
-
 
207
			while ((line = rd.readLine()) != null) {
-
 
208
				sb.append(line);
-
 
209
			}
-
 
210
		} catch (IOException e) {
-
 
211
			e.printStackTrace();
-
 
212
		}
-
 
213
		int i= sb.toString().indexOf("name=\"lt\" value=");
-
 
214
		char[] charArray = sb.toString().toCharArray();
-
 
215
		String lt = "";
-
 
216
		int j=0;
-
 
217
		for(j=i+16;j<=charArray.length;j++){
-
 
218
 
-
 
219
			if(charArray[j]==' '){
-
 
220
				break;
-
 
221
			}
-
 
222
		}
-
 
223
		lt = sb.substring(i+17,j-1);
-
 
224
		System.out.println("LT VALUE " + lt);
-
 
225
		i= sb.toString().indexOf("name=\"execution\" value=");
-
 
226
		charArray = sb.toString().toCharArray();
-
 
227
		String ex = "";
-
 
228
		j=0;
-
 
229
		for(j=i+24;j<=charArray.length;j++){
-
 
230
			if(charArray[j]==' '){
-
 
231
				break;
-
 
232
			}
-
 
233
		}
-
 
234
		ex = sb.substring(i+24,j-1);
-
 
235
		System.out.println("EXECUTION VALUE " + ex);
-
 
236
		HttpPost post = new HttpPost("http://selleraccounts.snapdeal.com/login?service=http%3A%2F%2Fseller.snapdeal.com%2Fj_spring_cas_security_check");
-
 
237
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
-
 
238
		nameValuePairs.add(new BasicNameValuePair("username",
-
 
239
		"spiceonlineretailvoi@gmail.com"));
-
 
240
		nameValuePairs.add(new BasicNameValuePair("password",
-
 
241
		"snapdealsaholic"));
-
 
242
		nameValuePairs.add(new BasicNameValuePair("_eventId","submit"));
-
 
243
		nameValuePairs.add(new BasicNameValuePair("execution",ex));
-
 
244
		nameValuePairs.add(new BasicNameValuePair("lt",lt));
-
 
245
		nameValuePairs.add(new BasicNameValuePair("submit","LOGIN"));
-
 
246
		post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
-
 
247
		response = httpClient.execute(post);
-
 
248
		rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
-
 
249
		line = "";
-
 
250
		while ((line = rd.readLine()) != null) {
-
 
251
			System.out.println(line);
-
 
252
		}
-
 
253
		get = new HttpGet("http://seller.snapdeal.com/pricing");
-
 
254
		response = httpClient.execute(get);
-
 
255
		rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
-
 
256
		while ((line = rd.readLine()) != null) {
-
 
257
			//System.out.println(line);
-
 
258
		}
-
 
259
		logger.info("----Login Successful into Snapdeal VOI----" );
-
 
260
	}
169
	public void run()
261
	public void run()
170
	{
262
	{
171
		try {
263
		try {
-
 
264
			if(voiUpdation){
-
 
265
				this.handleVoiLogin();
-
 
266
			}else{
172
			this.handleLogin();
267
				this.handleLogin();
-
 
268
			}
173
			this.updatePricing(this.price,this.supc,this.item,timestamp);
269
			this.updatePricing(this.price,this.supc,this.item,timestamp);
174
			boolean retry =true;
270
			boolean retry =true;
175
			while(retry){
271
			while(retry){
176
				Thread.sleep(2*60*1000);
272
				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");
273
				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");