mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 23:18:48 +00:00
parse lineLink for Germany
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@179 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
76026f46ce
commit
5812a35d67
6 changed files with 55 additions and 39 deletions
|
@ -456,7 +456,7 @@ public final class BahnProvider implements NetworkProvider
|
||||||
, Pattern.DOTALL);
|
, Pattern.DOTALL);
|
||||||
private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("<div class=\"sqdetailsDep trow\">\n(.+?)</div>", Pattern.DOTALL);
|
private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("<div class=\"sqdetailsDep trow\">\n(.+?)</div>", Pattern.DOTALL);
|
||||||
static final Pattern P_DEPARTURES_FINE = Pattern.compile(".*?" //
|
static final Pattern P_DEPARTURES_FINE = Pattern.compile(".*?" //
|
||||||
+ "<a href=\"http://mobile\\.bahn\\.de/bin/mobil/traininfo.exe/dox[^\"]*\">\n" //
|
+ "<a href=\"(http://mobile\\.bahn\\.de/bin/mobil/traininfo.exe/dox[^\"]*)\">\n" // lineLink
|
||||||
+ "<span class=\"bold\">(.*?)</span>\n" // line
|
+ "<span class=\"bold\">(.*?)</span>\n" // line
|
||||||
+ "</a>\n" //
|
+ "</a>\n" //
|
||||||
+ ">>\n" //
|
+ ">>\n" //
|
||||||
|
@ -504,14 +504,16 @@ public final class BahnProvider implements NetworkProvider
|
||||||
final Matcher mDepFine = P_DEPARTURES_FINE.matcher(mDepCoarse.group(1));
|
final Matcher mDepFine = P_DEPARTURES_FINE.matcher(mDepCoarse.group(1));
|
||||||
if (mDepFine.matches())
|
if (mDepFine.matches())
|
||||||
{
|
{
|
||||||
final String line = normalizeLine(ParserUtils.resolveEntities(mDepFine.group(1)));
|
final String lineLink = ParserUtils.resolveEntities(mDepFine.group(1));
|
||||||
|
|
||||||
final String destination = ParserUtils.resolveEntities(mDepFine.group(2));
|
final String line = normalizeLine(ParserUtils.resolveEntities(mDepFine.group(2)));
|
||||||
|
|
||||||
|
final String destination = ParserUtils.resolveEntities(mDepFine.group(3));
|
||||||
|
|
||||||
final Calendar current = new GregorianCalendar();
|
final Calendar current = new GregorianCalendar();
|
||||||
current.setTime(currentTime);
|
current.setTime(currentTime);
|
||||||
final Calendar parsed = new GregorianCalendar();
|
final Calendar parsed = new GregorianCalendar();
|
||||||
parsed.setTime(ParserUtils.parseTime(mDepFine.group(3)));
|
parsed.setTime(ParserUtils.parseTime(mDepFine.group(4)));
|
||||||
parsed.set(Calendar.YEAR, current.get(Calendar.YEAR));
|
parsed.set(Calendar.YEAR, current.get(Calendar.YEAR));
|
||||||
parsed.set(Calendar.MONTH, current.get(Calendar.MONTH));
|
parsed.set(Calendar.MONTH, current.get(Calendar.MONTH));
|
||||||
parsed.set(Calendar.DAY_OF_MONTH, current.get(Calendar.DAY_OF_MONTH));
|
parsed.set(Calendar.DAY_OF_MONTH, current.get(Calendar.DAY_OF_MONTH));
|
||||||
|
@ -520,23 +522,23 @@ public final class BahnProvider implements NetworkProvider
|
||||||
final Date plannedTime = parsed.getTime();
|
final Date plannedTime = parsed.getTime();
|
||||||
|
|
||||||
Date predictedTime = null;
|
Date predictedTime = null;
|
||||||
if (mDepFine.group(4) != null)
|
if (mDepFine.group(5) != null)
|
||||||
{
|
{
|
||||||
predictedTime = plannedTime;
|
predictedTime = plannedTime;
|
||||||
}
|
}
|
||||||
else if (mDepFine.group(5) != null)
|
else if (mDepFine.group(6) != null)
|
||||||
{
|
{
|
||||||
final int delay = Integer.parseInt(mDepFine.group(5));
|
final int delay = Integer.parseInt(mDepFine.group(6));
|
||||||
parsed.add(Calendar.MINUTE, delay);
|
parsed.add(Calendar.MINUTE, delay);
|
||||||
predictedTime = parsed.getTime();
|
predictedTime = parsed.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
final String message = ParserUtils.resolveEntities(mDepFine.group(6));
|
final String message = ParserUtils.resolveEntities(mDepFine.group(7));
|
||||||
|
|
||||||
final String position = ParserUtils.resolveEntities(mDepFine.group(7));
|
final String position = ParserUtils.resolveEntities(mDepFine.group(8));
|
||||||
|
|
||||||
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null,
|
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null,
|
||||||
position, 0, destination, message);
|
lineLink, position, 0, destination, message);
|
||||||
if (!departures.contains(dep))
|
if (!departures.contains(dep))
|
||||||
departures.add(dep);
|
departures.add(dep);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,18 +28,20 @@ public final class Departure
|
||||||
final public Date predictedTime;
|
final public Date predictedTime;
|
||||||
final public String line;
|
final public String line;
|
||||||
final public int[] lineColors;
|
final public int[] lineColors;
|
||||||
|
final public String lineLink;
|
||||||
final public String position;
|
final public String position;
|
||||||
final public int destinationId;
|
final public int destinationId;
|
||||||
final public String destination;
|
final public String destination;
|
||||||
final public String message;
|
final public String message;
|
||||||
|
|
||||||
public Departure(final Date plannedTime, final Date predictedTime, final String line, final int[] lineColors, final String position,
|
public Departure(final Date plannedTime, final Date predictedTime, final String line, final int[] lineColors, final String lineLink,
|
||||||
final int destinationId, final String destination, final String message)
|
final String position, final int destinationId, final String destination, final String message)
|
||||||
{
|
{
|
||||||
this.plannedTime = plannedTime;
|
this.plannedTime = plannedTime;
|
||||||
this.predictedTime = predictedTime;
|
this.predictedTime = predictedTime;
|
||||||
this.line = line;
|
this.line = line;
|
||||||
this.lineColors = lineColors;
|
this.lineColors = lineColors;
|
||||||
|
this.lineLink = lineLink;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.destinationId = destinationId;
|
this.destinationId = destinationId;
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
|
@ -53,6 +55,7 @@ public final class Departure
|
||||||
this.predictedTime = null;
|
this.predictedTime = null;
|
||||||
this.line = line;
|
this.line = line;
|
||||||
this.lineColors = lineColors;
|
this.lineColors = lineColors;
|
||||||
|
this.lineLink = null;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.destinationId = destinationId;
|
this.destinationId = destinationId;
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
|
|
|
@ -572,7 +572,7 @@ public class OebbProvider implements NetworkProvider
|
||||||
|
|
||||||
final String position = mDepFine.group(7) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(7)) : null;
|
final String position = mDepFine.group(7) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(7)) : null;
|
||||||
|
|
||||||
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null,
|
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null, null,
|
||||||
position, destinationId, destination, null);
|
position, destinationId, destination, null);
|
||||||
|
|
||||||
if (!departures.contains(dep))
|
if (!departures.contains(dep))
|
||||||
|
|
|
@ -568,7 +568,7 @@ public class RmvProvider implements NetworkProvider
|
||||||
|
|
||||||
final String position = ParserUtils.resolveEntities(ParserUtils.selectNotNull(mDepFine.group(5), mDepFine.group(6)));
|
final String position = ParserUtils.resolveEntities(ParserUtils.selectNotNull(mDepFine.group(5), mDepFine.group(6)));
|
||||||
|
|
||||||
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null,
|
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null, null,
|
||||||
position, 0, destination, null);
|
position, 0, destination, null);
|
||||||
|
|
||||||
if (!departures.contains(dep))
|
if (!departures.contains(dep))
|
||||||
|
|
|
@ -589,7 +589,7 @@ public final class VbbProvider implements NetworkProvider
|
||||||
|
|
||||||
final String destination = ParserUtils.resolveEntities(mDepFine.group(live ? 4 : 5));
|
final String destination = ParserUtils.resolveEntities(mDepFine.group(live ? 4 : 5));
|
||||||
|
|
||||||
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line) : null, position,
|
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line) : null, null, position,
|
||||||
destinationId, destination, null);
|
destinationId, destination, null);
|
||||||
if (!departures.contains(dep))
|
if (!departures.contains(dep))
|
||||||
departures.add(dep);
|
departures.add(dep);
|
||||||
|
|
|
@ -51,7 +51,8 @@ public class BahnProviderTest
|
||||||
+ "<br />\n" //
|
+ "<br />\n" //
|
||||||
+ "<span class=\"bold\">10:42</span>Gl. 1");
|
+ "<span class=\"bold\">10:42</span>Gl. 1");
|
||||||
|
|
||||||
assertNotNull(m.group(7)); // position
|
assertNotNull(m.group(1)); // lineLink
|
||||||
|
assertNotNull(m.group(8)); // position
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -66,8 +67,9 @@ public class BahnProviderTest
|
||||||
+ "<br />\n" //
|
+ "<br />\n" //
|
||||||
+ "<span class=\"bold\">21:58</span> <span class=\"green bold\">pünktl.</span>, Gl. 13");
|
+ "<span class=\"bold\">21:58</span> <span class=\"green bold\">pünktl.</span>, Gl. 13");
|
||||||
|
|
||||||
assertNotNull(m.group(4)); // onTime
|
assertNotNull(m.group(1)); // lineLink
|
||||||
assertNotNull(m.group(7)); // position
|
assertNotNull(m.group(5)); // onTime
|
||||||
|
assertNotNull(m.group(8)); // position
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -82,9 +84,10 @@ public class BahnProviderTest
|
||||||
+ "<br />\n" //
|
+ "<br />\n" //
|
||||||
+ "<span class=\"bold\">07:02</span> <span class=\"red\">ca. +5</span>, <span class=\"red\">Fährt heute nur bis Düsseldorf Hbf</span>, Gl. 10");
|
+ "<span class=\"bold\">07:02</span> <span class=\"red\">ca. +5</span>, <span class=\"red\">Fährt heute nur bis Düsseldorf Hbf</span>, Gl. 10");
|
||||||
|
|
||||||
assertNotNull(m.group(5)); // delay
|
assertNotNull(m.group(1)); // lineLink
|
||||||
assertNotNull(m.group(6)); // message
|
assertNotNull(m.group(6)); // delay
|
||||||
assertNotNull(m.group(7)); // position
|
assertNotNull(m.group(7)); // message
|
||||||
|
assertNotNull(m.group(8)); // position
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -99,8 +102,9 @@ public class BahnProviderTest
|
||||||
+ "<br />\n" //
|
+ "<br />\n" //
|
||||||
+ "<span class=\"bold\">17:10</span> <span class=\"green bold\">pünktl.</span>, <span class=\"red\">heute Gl. 7 </span>");
|
+ "<span class=\"bold\">17:10</span> <span class=\"green bold\">pünktl.</span>, <span class=\"red\">heute Gl. 7 </span>");
|
||||||
|
|
||||||
assertNotNull(m.group(4)); // onTime
|
assertNotNull(m.group(1)); // lineLink
|
||||||
assertNotNull(m.group(7)); // position
|
assertNotNull(m.group(5)); // onTime
|
||||||
|
assertNotNull(m.group(8)); // position
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -115,9 +119,10 @@ public class BahnProviderTest
|
||||||
+ "<br />\n" //
|
+ "<br />\n" //
|
||||||
+ "<span class=\"bold\">19:57</span> <span class=\"green bold\">pünktl.</span>, <span class=\"red\">Änderung im Zuglauf!</span>, <span class=\"red\">heute Gl. 7 </span>");
|
+ "<span class=\"bold\">19:57</span> <span class=\"green bold\">pünktl.</span>, <span class=\"red\">Änderung im Zuglauf!</span>, <span class=\"red\">heute Gl. 7 </span>");
|
||||||
|
|
||||||
assertNotNull(m.group(4)); // onTime
|
assertNotNull(m.group(1)); // lineLink
|
||||||
assertNotNull(m.group(6)); // message
|
assertNotNull(m.group(5)); // onTime
|
||||||
assertNotNull(m.group(7)); // position
|
assertNotNull(m.group(7)); // message
|
||||||
|
assertNotNull(m.group(8)); // position
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -132,7 +137,8 @@ public class BahnProviderTest
|
||||||
+ "<br />\n" //
|
+ "<br />\n" //
|
||||||
+ "<span class=\"bold\">04:52</span> k.A., Gl. 3");
|
+ "<span class=\"bold\">04:52</span> k.A., Gl. 3");
|
||||||
|
|
||||||
assertNotNull(m.group(7)); // position
|
assertNotNull(m.group(1)); // lineLink
|
||||||
|
assertNotNull(m.group(8)); // position
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -147,8 +153,9 @@ public class BahnProviderTest
|
||||||
+ "<br />\n" //
|
+ "<br />\n" //
|
||||||
+ "<span class=\"bold\">14:49</span> <span class=\"green bold\">pünktl.</span>, Gl. 1,<br/><span class=\"red\">Ersatzzug für<a class=\"red underline\" href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/611619/369020/735680/163967/80?ld=96159&rt=1&use_realtime_filter=1&date=10.09.10&time=14:49&station_evaId=8000220&station_type=dep&\">RB 5416</a></span>");
|
+ "<span class=\"bold\">14:49</span> <span class=\"green bold\">pünktl.</span>, Gl. 1,<br/><span class=\"red\">Ersatzzug für<a class=\"red underline\" href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/611619/369020/735680/163967/80?ld=96159&rt=1&use_realtime_filter=1&date=10.09.10&time=14:49&station_evaId=8000220&station_type=dep&\">RB 5416</a></span>");
|
||||||
|
|
||||||
assertNotNull(m.group(4)); // onTime
|
assertNotNull(m.group(1)); // lineLink
|
||||||
assertNotNull(m.group(7)); // position
|
assertNotNull(m.group(5)); // onTime
|
||||||
|
assertNotNull(m.group(8)); // position
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -163,7 +170,8 @@ public class BahnProviderTest
|
||||||
+ "<br />\n" //
|
+ "<br />\n" //
|
||||||
+ "<span class=\"bold\">10:27</span>, <span class=\"red\">Zug fällt aus</span>,<br/><a class=\"red underline\" href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/144627/793698/280606/92094/80?ld=96159&rt=1&use_realtime_filter=1&date=08.09.10&time=10:27&station_evaId=8001647&station_type=dep&\"><span class=\"red\">Ersatzzug S </a></span>");
|
+ "<span class=\"bold\">10:27</span>, <span class=\"red\">Zug fällt aus</span>,<br/><a class=\"red underline\" href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/144627/793698/280606/92094/80?ld=96159&rt=1&use_realtime_filter=1&date=08.09.10&time=10:27&station_evaId=8001647&station_type=dep&\"><span class=\"red\">Ersatzzug S </a></span>");
|
||||||
|
|
||||||
assertNotNull(m.group(6)); // message
|
assertNotNull(m.group(1)); // lineLink
|
||||||
|
assertNotNull(m.group(7)); // message
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -178,8 +186,9 @@ public class BahnProviderTest
|
||||||
+ "<br />\n" //
|
+ "<br />\n" //
|
||||||
+ "<span class=\"bold\">00:18</span>, <span class=\"red\">Zug fällt aus</span>, Gl. 4,<br/><a class=\"red underline\" href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/843399/1026627/462944/49661/80?ld=96159&rt=1&use_realtime_filter=1&date=09.09.10&time=00:18&station_evaId=8001844&station_type=dep&\"><span class=\"red\">Ersatzzug RB 30535</a></span>");
|
+ "<span class=\"bold\">00:18</span>, <span class=\"red\">Zug fällt aus</span>, Gl. 4,<br/><a class=\"red underline\" href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/843399/1026627/462944/49661/80?ld=96159&rt=1&use_realtime_filter=1&date=09.09.10&time=00:18&station_evaId=8001844&station_type=dep&\"><span class=\"red\">Ersatzzug RB 30535</a></span>");
|
||||||
|
|
||||||
assertNotNull(m.group(6)); // message
|
assertNotNull(m.group(1)); // lineLink
|
||||||
assertNotNull(m.group(7)); // position
|
assertNotNull(m.group(7)); // message
|
||||||
|
assertNotNull(m.group(8)); // position
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -194,8 +203,9 @@ public class BahnProviderTest
|
||||||
+ "<br />\n" //
|
+ "<br />\n" //
|
||||||
+ "<span class=\"bold\">10:59</span> <span class=\"green bold\">pünktl.</span>, <span class=\"red\">Änderung im Zuglauf!</span>, <span class=\"red\">Fährt heute nur bis Köln-Dellbrück</span>, Gl. 1");
|
+ "<span class=\"bold\">10:59</span> <span class=\"green bold\">pünktl.</span>, <span class=\"red\">Änderung im Zuglauf!</span>, <span class=\"red\">Fährt heute nur bis Köln-Dellbrück</span>, Gl. 1");
|
||||||
|
|
||||||
assertNotNull(m.group(4)); // onTime
|
assertNotNull(m.group(1)); // lineLink
|
||||||
assertNotNull(m.group(6)); // message
|
assertNotNull(m.group(5)); // onTime
|
||||||
|
assertNotNull(m.group(7)); // message
|
||||||
assertNotNull(m.group(7)); // position
|
assertNotNull(m.group(7)); // position
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,8 +221,9 @@ public class BahnProviderTest
|
||||||
+ "<br />\n" //
|
+ "<br />\n" //
|
||||||
+ "<span class=\"bold\">22:58</span> <span class=\"green bold\">pünktl.</span>, Gl. 2,<br/> <span class=\"red\">Sonderzug</span>");
|
+ "<span class=\"bold\">22:58</span> <span class=\"green bold\">pünktl.</span>, Gl. 2,<br/> <span class=\"red\">Sonderzug</span>");
|
||||||
|
|
||||||
assertNotNull(m.group(4)); // onTime
|
assertNotNull(m.group(1)); // lineLink
|
||||||
assertNotNull(m.group(7)); // position
|
assertNotNull(m.group(5)); // onTime
|
||||||
|
assertNotNull(m.group(8)); // position
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertFineConnectionDetails(String s)
|
private void assertFineConnectionDetails(String s)
|
||||||
|
@ -230,9 +241,9 @@ public class BahnProviderTest
|
||||||
|
|
||||||
// ParserUtils.printGroups(m);
|
// ParserUtils.printGroups(m);
|
||||||
|
|
||||||
assertNotNull(m.group(1)); // line
|
assertNotNull(m.group(2)); // line
|
||||||
assertNotNull(m.group(2)); // destination
|
assertNotNull(m.group(3)); // destination
|
||||||
assertNotNull(m.group(3)); // time
|
assertNotNull(m.group(4)); // time
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue