79 |
departureBean.notifications.addAll(tempBean.notifications); |
departureBean.notifications.addAll(tempBean.notifications); |
80 |
} |
} |
81 |
|
|
82 |
|
if (departureBean.departureEntries.size() == 0) { |
83 |
|
logger.info("No departures found for station " + stationID); |
84 |
|
} |
85 |
|
|
86 |
Collections.sort( departureBean.departureEntries ); |
Collections.sort( departureBean.departureEntries ); |
87 |
|
|
88 |
|
|
173 |
|
|
174 |
String trainNumber = fields.get(2).text(); |
String trainNumber = fields.get(2).text(); |
175 |
if (type == TrainType.STOG) //If it is S-train we need to extract the trainNumber |
if (type == TrainType.STOG) //If it is S-train we need to extract the trainNumber |
176 |
trainNumber = trainNumber + " " + extractTrainNumber(fields.get(2)); |
trainNumber = trainNumber + " " + extractTrainNumberAzure(fields.get(2)); |
177 |
departure.setTrainNumber(trainNumber); |
departure.setTrainNumber(trainNumber); |
178 |
|
|
179 |
String destination = fields.get(3).text(); |
String destination = fields.get(3).text(); |
218 |
return departureBean; |
return departureBean; |
219 |
} |
} |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
public static String cleanText(String input) { |
224 |
|
//apparently JSoup translates characters on www.bane.dk to 0xA0 |
225 |
|
return input.replace((char) 0xA0, (char)0x20).trim(); |
226 |
|
} |
227 |
|
|
228 |
public DepartureBean lookupDeparturesWwwSite(String stationcode, TrainType trainType, boolean arrival) throws Exception { |
public DepartureBean lookupDeparturesWwwSite(String stationcode, TrainType trainType, boolean arrival) throws Exception { |
229 |
|
|
230 |
DepartureBean departureBean = new DepartureBean(); |
DepartureBean departureBean = new DepartureBean(); |
253 |
|
|
254 |
|
|
255 |
|
|
256 |
String time = fields.get(0).getAllElements().get(2).text(); |
String time = cleanText( fields.get(0).getAllElements().get(2).text() ); |
257 |
if (time.equals("")) |
if (time.equals("")) |
258 |
time = "0:00"; //Bane.dk bug work-around |
time = "0:00"; //Bane.dk bug work-around |
259 |
departure.setTime(time); |
departure.setTime(time); |
261 |
int updated = extractUpdated( fields.get(1) ); |
int updated = extractUpdated( fields.get(1) ); |
262 |
departure.setUpdated(updated); |
departure.setUpdated(updated); |
263 |
|
|
264 |
String trainNumber = fields.get(2).text(); |
String trainNumber = cleanText( fields.get(2).text() ); |
265 |
if (type.equalsIgnoreCase("S2")) //If it is S-train we need to extract the trainNumber |
if (type.equalsIgnoreCase("S2")) //If it is S-train we need to extract the trainNumber |
266 |
trainNumber = trainNumber + " " + extractTrainNumber(fields.get(2)); |
trainNumber = trainNumber + " " + extractTrainNumberWww(fields.get(2)); |
267 |
departure.setTrainNumber(trainNumber); |
departure.setTrainNumber(trainNumber); |
268 |
|
|
269 |
String destination = fields.get(3).text(); |
String destination = cleanText( fields.get(3).text() ); |
270 |
departure.setDestination(destination); |
departure.setDestination(destination); |
271 |
|
|
272 |
String origin = fields.get(4).text(); |
String origin = cleanText( fields.get(4).text() ); |
273 |
departure.setOrigin(origin); |
departure.setOrigin(origin); |
274 |
|
|
275 |
String location = fields.get(5).text(); |
String location = cleanText( fields.get(5).text() ); |
276 |
departure.setLocation(location); |
departure.setLocation(location); |
277 |
|
|
278 |
String status = fields.get(6).text().trim(); |
String status = cleanText( fields.get(6).text() ); |
279 |
departure.setStatus(status); |
departure.setStatus(status); |
280 |
|
|
281 |
String note = extractNote( fields.get(7) ); |
String note = cleanText( extractNote( fields.get(7) ) ); |
282 |
departure.setNote(note); |
departure.setNote(note); |
283 |
|
|
284 |
departure.setType(type); |
departure.setType(type); |
323 |
if (elems.size() > 0 && note.charAt(note.length()-1) == 'i') |
if (elems.size() > 0 && note.charAt(note.length()-1) == 'i') |
324 |
note = note.substring(0,note.length() -1 ); |
note = note.substring(0,note.length() -1 ); |
325 |
|
|
326 |
return note; |
return note.trim(); |
327 |
} |
} |
328 |
|
|
329 |
private String extractTrainNumber(Element trainTd) { |
private String extractTrainNumberAzure(Element trainTd) { |
330 |
Element anchorElement = trainTd.getElementsByTag("a").get(0); |
Element anchorElement = trainTd.getElementsByTag("a").get(0); |
331 |
String href = anchorElement.attr("href"); |
String href = anchorElement.attr("href"); |
332 |
|
|
336 |
return number; |
return number; |
337 |
} |
} |
338 |
|
|
339 |
|
private String extractTrainNumberWww(Element trainTd) { |
340 |
|
String number = ""; |
341 |
|
Element anchorElement = trainTd.getElementsByTag("a").get(0); |
342 |
|
String href = anchorElement.attr("href"); |
343 |
|
String argstring = href.substring( href.indexOf('?') + 1); |
344 |
|
|
345 |
|
String args[] = argstring.split("&"); |
346 |
|
for (String arg : args) { |
347 |
|
String pair[] = arg.split("="); // Key=pair[0], Value=pair[1] |
348 |
|
|
349 |
|
if (pair[0].equalsIgnoreCase("TogNr")) |
350 |
|
number = pair[1]; |
351 |
|
} |
352 |
|
|
353 |
|
|
354 |
|
return number; |
355 |
|
} |
356 |
|
|
357 |
|
|
358 |
//test |
//test |
359 |
/* |
/* |
360 |
public static void main(String args[]) throws Exception { |
public static void main(String args[]) throws Exception { |