Subversion Repositories SmartDukaan

Rev

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

Rev 9828 Rev 9858
Line 12... Line 12...
12
import java.io.FileInputStream;
12
import java.io.FileInputStream;
13
import java.io.FileNotFoundException;
13
import java.io.FileNotFoundException;
14
import java.io.FileOutputStream;
14
import java.io.FileOutputStream;
15
import java.io.IOException;
15
import java.io.IOException;
16
import java.io.InputStreamReader;
16
import java.io.InputStreamReader;
-
 
17
import java.io.UnsupportedEncodingException;
17
import java.text.SimpleDateFormat;
18
import java.text.SimpleDateFormat;
18
import java.util.ArrayList;
19
import java.util.ArrayList;
19
import java.util.HashMap;
20
import java.util.HashMap;
20
import java.util.List;
21
import java.util.List;
21
import java.util.Map;
22
import java.util.Map;
Line 103... Line 104...
103
			snapdealItemMap.put(snapdealItem.getSkuAtSnapdeal(),snapdealItem);
104
			snapdealItemMap.put(snapdealItem.getSkuAtSnapdeal(),snapdealItem);
104
			itemSnapdealMap.put(snapdealItem.getItem_id(), snapdealItem);
105
			itemSnapdealMap.put(snapdealItem.getItem_id(), snapdealItem);
105
		}
106
		}
106
 
107
 
107
	}
108
	}
108
 
-
 
109
 
-
 
110
	public static void main(String... args) throws IOException, InterruptedException{
109
	public static void handleLogin() throws ClientProtocolException, IOException{
111
		HttpPost post = new HttpPost("http://seller.snapdeal.com/login_security_check?spring-security-redirect=http://seller.snapdeal.com/inventory&");
110
		HttpGet get = new HttpGet("http://selleraccounts.snapdeal.com/keymaker/login");
112
		HttpGet get; 
-
 
113
		BufferedReader rd= null;
-
 
114
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
-
 
115
		nameValuePairs.add(new BasicNameValuePair("j_username",
-
 
116
		"khushal.bhatia@saholic.com"));
-
 
117
		nameValuePairs.add(new BasicNameValuePair("j_password",
-
 
118
		"sonline"));
-
 
119
		post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
-
 
120
		HttpResponse response = null;
111
		HttpResponse response = null;
121
		try {
112
		try {
122
			response = client.execute(post);
113
			response = client.execute(get);
123
		} catch (ClientProtocolException e) {
114
		} catch (ClientProtocolException e) {
124
			// TODO Auto-generated catch block
115
			// TODO Auto-generated catch block
125
			e.printStackTrace();
116
			e.printStackTrace();
126
		} catch (IOException e) {
117
		} catch (IOException e) {
127
			// TODO Auto-generated catch block
118
			// TODO Auto-generated catch block
128
			e.printStackTrace();
119
			e.printStackTrace();
129
		}
120
		}
-
 
121
		BufferedReader rd = null;
130
		try {
122
		try {
131
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
123
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
132
		} catch (IllegalStateException e1) {
124
		} catch (IllegalStateException e1) {
133
			// TODO Auto-generated catch block
125
			// TODO Auto-generated catch block
134
			e1.printStackTrace();
126
			e1.printStackTrace();
135
		} catch (IOException e1) {
127
		} catch (IOException e1) {
136
			// TODO Auto-generated catch block
128
			// TODO Auto-generated catch block
137
			e1.printStackTrace();
129
			e1.printStackTrace();
138
		}
130
		}
139
		String line = "";
131
		String line = "";
-
 
132
		StringBuffer sb = new StringBuffer();
140
		try {
133
		try {
141
			while ((line = rd.readLine()) != null) {
134
			while ((line = rd.readLine()) != null) {
-
 
135
				sb.append(line);
142
				//System.out.println(line);
136
				System.out.println(line);
143
			}
137
			}
144
		} catch (IOException e) {
138
		} catch (IOException e) {
145
			// TODO Auto-generated catch block
139
			// TODO Auto-generated catch block
146
			e.printStackTrace();
140
			e.printStackTrace();
147
		}
141
		}
-
 
142
		int i= sb.toString().indexOf("name=\"lt\" value=");
-
 
143
		char[] charArray = sb.toString().toCharArray();
-
 
144
		String lt = "";
-
 
145
		int j=0;
-
 
146
		for(j=i+16;j<=charArray.length;j++){
-
 
147
 
-
 
148
			if(charArray[j]==' '){
-
 
149
				break;
-
 
150
			}
-
 
151
		}
-
 
152
		lt = sb.substring(i+17,j-1);
-
 
153
		System.out.println("LT VALUE " + lt);
-
 
154
		i= sb.toString().indexOf("name=\"execution\" value=");
-
 
155
		charArray = sb.toString().toCharArray();
-
 
156
		String ex = "";
-
 
157
		j=0;
-
 
158
		for(j=i+24;j<=charArray.length;j++){
-
 
159
			if(charArray[j]==' '){
-
 
160
				break;
-
 
161
			}
-
 
162
		}
-
 
163
		ex = sb.substring(i+24,j-1);
-
 
164
		System.out.println("EXECUTION VALUE " + ex);
-
 
165
		HttpPost post = new HttpPost("http://selleraccounts.snapdeal.com/keymaker/login");
-
 
166
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
-
 
167
		nameValuePairs.add(new BasicNameValuePair("username",
-
 
168
		"khushal.bhatia@saholic.com"));
-
 
169
		nameValuePairs.add(new BasicNameValuePair("password",
-
 
170
		"sonline"));
-
 
171
		nameValuePairs.add(new BasicNameValuePair("_eventId","submit"));
-
 
172
		nameValuePairs.add(new BasicNameValuePair("execution",ex));
-
 
173
		nameValuePairs.add(new BasicNameValuePair("lt",lt));
-
 
174
		nameValuePairs.add(new BasicNameValuePair("submit","LOGIN"));
-
 
175
		post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
-
 
176
		response = client.execute(post);
-
 
177
		rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
-
 
178
		line = "";
-
 
179
		while ((line = rd.readLine()) != null) {
-
 
180
			//System.out.println(line);
-
 
181
		}
-
 
182
		get = new HttpGet("http://seller.snapdeal.com/pricing/");
-
 
183
		response = client.execute(get);
-
 
184
		rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
-
 
185
		while ((line = rd.readLine()) != null) {
-
 
186
			//System.out.println(line);
-
 
187
		}
-
 
188
	}
-
 
189
 
-
 
190
 
-
 
191
	public static void main(String... args) throws IOException, InterruptedException{
-
 
192
		handleLogin();
-
 
193
		HttpGet get; 
-
 
194
		BufferedReader rd= null;
148
		Gson gson = new Gson();
195
		Gson gson = new Gson();
149
		int i = 1;
196
		int i = 1;
150
		boolean exitfetchingcurrent = true;
197
		boolean exitfetchingcurrent = true;
151
		System.out.println("Fetching current prices");
198
		System.out.println("Fetching current prices");
-
 
199
		HttpResponse response;
152
		while(exitfetchingcurrent){
200
		while(exitfetchingcurrent){
153
			get = new HttpGet("http://seller.snapdeal.com/pricing/search?gridType=normal&_search=false&nd="+time+"&rows=30&page="+i+"&sidx=&sord=asc");
201
			get = new HttpGet("http://seller.snapdeal.com/pricing/search?gridType=normal&_search=false&nd="+time+"&rows=30&page="+i+"&sidx=&sord=asc");
154
			response = client.execute(get);
202
			response = client.execute(get);
155
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
203
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
156
			currentPricingItems = (CurrentPricingItems) gson.fromJson(rd, CurrentPricingItems.class);
204
			currentPricingItems = (CurrentPricingItems) gson.fromJson(rd, CurrentPricingItems.class);
Line 163... Line 211...
163
			else{
211
			else{
164
				exitfetchingcurrent = false;
212
				exitfetchingcurrent = false;
165
			}
213
			}
166
			i++;
214
			i++;
167
		}
215
		}
168
 
-
 
169
		FileInputStream fis = new FileInputStream("/root/code/trunk/SnapDealFeeds/SellerPricing.xls");
216
		FileInputStream fis = new FileInputStream("/root/code/trunk/SnapDealFeeds/SellerPricing.xls");
170
		Workbook hwb = new HSSFWorkbook(fis);
217
		Workbook hwb = new HSSFWorkbook(fis);
171
		Sheet sheet = hwb.getSheetAt(0);
218
		Sheet sheet = hwb.getSheetAt(0);
172
		Row row;
219
		Row row;
173
		int iterator = 1;
220
		int iterator = 1;
Line 201... Line 248...
201
				hwb.write(fileOut);
248
				hwb.write(fileOut);
202
			} catch (IOException e) {
249
			} catch (IOException e) {
203
				// TODO Auto-generated catch block
250
				// TODO Auto-generated catch block
204
				e.printStackTrace();
251
				e.printStackTrace();
205
			}
252
			}
206
			post = new HttpPost("http://seller.snapdeal.com/pricing/upload");
253
			HttpPost post = new HttpPost("http://seller.snapdeal.com/pricing/upload");
207
			File file = new File(SNAPDEAL_PRICING_SHEET);
254
			File file = new File(SNAPDEAL_PRICING_SHEET);
208
			MultipartEntity mpEntity = new MultipartEntity();
255
			MultipartEntity mpEntity = new MultipartEntity();
209
			ContentBody cbFile = new FileBody(file,"application/vnd.ms-excel");
256
			ContentBody cbFile = new FileBody(file,"application/vnd.ms-excel");
210
			mpEntity.addPart("file", cbFile);
257
			mpEntity.addPart("file", cbFile);
211
			post.setEntity(mpEntity);
258
			post.setEntity(mpEntity);
Line 215... Line 262...
215
			} catch (IllegalStateException e1) {
262
			} catch (IllegalStateException e1) {
216
				e1.printStackTrace();
263
				e1.printStackTrace();
217
			} catch (IOException e1) {
264
			} catch (IOException e1) {
218
				e1.printStackTrace();
265
				e1.printStackTrace();
219
			}
266
			}
220
			line = "";
267
			String line = "";
221
			String feedresponse = null;
268
			String feedresponse = null;
222
			try {
269
			try {
223
				while ((line = rd.readLine()) != null) {
270
				while ((line = rd.readLine()) != null) {
224
					feedresponse = line;
271
					feedresponse = line;
225
				}
272
				}