mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 05:18:46 +00:00
parse multiple messages
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@150 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
138be61f7f
commit
d7aa7aa4f1
2 changed files with 46 additions and 11 deletions
|
@ -446,12 +446,17 @@ public final class BahnProvider implements NetworkProvider
|
|||
, 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(".*?" //
|
||||
+ "<span class=\"bold\">(.*?)</span>.*?" // line
|
||||
+ ">>\n\\s*(.+?)\\s*\n<br />\n" // destination
|
||||
+ "<a href=\"http://mobile\\.bahn\\.de/bin/mobil/traininfo.exe/dox[^\"]*\">\n" //
|
||||
+ "<span class=\"bold\">(.*?)</span>\n" // line
|
||||
+ "</a>\n" //
|
||||
+ ">>\n" //
|
||||
+ "\\s*(.+?)\\s*\n" // destination
|
||||
+ "<br />\n" //
|
||||
+ "<span class=\"bold\">(\\d{1,2}:\\d{2})</span>" // time
|
||||
+ "(?: <span class=\"[\\w ]*\">(?:(pünktl\\.)|ca. \\+(\\d+))</span>)?" // ontime, delay
|
||||
+ "(?: k\\.A\\.)?" //
|
||||
+ "(?:, <span class=\"red\">([^<]*)</span>)?" // message
|
||||
+ "(?:,<br/><a[^>]*><span class=\"red\">[^<]*</a></span>)?" // (ersatzzug message)
|
||||
+ "(?:(?:, )?(?:<span class=\"red\">heute )?(Gl\\. " + ParserUtils.P_PLATFORM + ")(?:\\s*</span>)?)?" // position
|
||||
, Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_URI_STATION_ID = Pattern.compile("input=(\\d+)");
|
||||
|
|
|
@ -42,7 +42,7 @@ public class BahnProviderTest
|
|||
@Test
|
||||
public void departureWithPlatform()
|
||||
{
|
||||
assertFineDepartures("" //
|
||||
final Matcher m = assertFineDepartures("" //
|
||||
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/731061/244203/590672/51649/80/si=8100352&bt=dep&ti=10:42&pt=10:42&p=1111111111&date=01.09.10&max=10&rt=1&&\">\n" //
|
||||
+ "<span class=\"bold\">S 1</span>\n" //
|
||||
+ "</a>\n" //
|
||||
|
@ -50,12 +50,14 @@ public class BahnProviderTest
|
|||
+ "Gänserndorf\n" //
|
||||
+ "<br />\n" //
|
||||
+ "<span class=\"bold\">10:42</span>Gl. 1");
|
||||
|
||||
assertNotNull(m.group(7)); // position
|
||||
}
|
||||
|
||||
@Test
|
||||
public void departureWithOnTime()
|
||||
{
|
||||
assertFineDepartures("" //
|
||||
final Matcher m = assertFineDepartures("" //
|
||||
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/438441/245165/958/145668/80/si=8011160&bt=dep&ti=21:47&pt=21:47&p=1111101&date=05.09.10&max=10&rt=1&&\">\n" //
|
||||
+ "<span class=\"bold\">RE 38148</span>\n" //
|
||||
+ "</a>\n" //
|
||||
|
@ -63,12 +65,14 @@ public class BahnProviderTest
|
|||
+ "Rathenow\n" //
|
||||
+ "<br />\n" //
|
||||
+ "<span class=\"bold\">21:58</span> <span class=\"green bold\">pünktl.</span>, Gl. 13");
|
||||
|
||||
assertNotNull(m.group(7)); // position
|
||||
}
|
||||
|
||||
@Test
|
||||
public void departureWithMessage()
|
||||
{
|
||||
assertFineDepartures("" //
|
||||
final Matcher m = assertFineDepartures("" //
|
||||
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/551037/330609/12448/177455/80/si=405341&bt=dep&ti=07:08&pt=07:08&p=1111111111&date=06.09.10&max=10&rt=1&&\">\n" //
|
||||
+ "<span class=\"bold\">ICE 824</span>\n" //
|
||||
+ "</a>\n" //
|
||||
|
@ -76,12 +80,15 @@ public class BahnProviderTest
|
|||
+ "Dortmund Hbf\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");
|
||||
|
||||
assertNotNull(m.group(6)); // message
|
||||
assertNotNull(m.group(7)); // position
|
||||
}
|
||||
|
||||
@Test
|
||||
public void departureUpdatedPosition()
|
||||
{
|
||||
assertFineDepartures("" //
|
||||
final Matcher m = assertFineDepartures("" //
|
||||
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/492282/296365/292060/18065/80/si=8000320&bt=dep&ti=17:08&pt=17:08&p=1111111111&date=07.09.10&max=10&rt=1&&\">\n" //
|
||||
+ "<span class=\"bold\">RB 30240</span>\n" //
|
||||
+ "</a>\n" //
|
||||
|
@ -89,12 +96,14 @@ public class BahnProviderTest
|
|||
+ "Holzkirchen\n" //
|
||||
+ "<br />\n" //
|
||||
+ "<span class=\"bold\">17:10</span> <span class=\"green bold\">pünktl.</span>, <span class=\"red\">heute Gl. 7 </span>");
|
||||
|
||||
assertNotNull(m.group(7)); // position
|
||||
}
|
||||
|
||||
@Test
|
||||
public void departureMessageAndUpdatedPosition()
|
||||
{
|
||||
assertFineDepartures("" //
|
||||
final Matcher m = assertFineDepartures("" //
|
||||
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/220206/221797/157782/5489/80/si=727269&bt=dep&ti=19:56&pt=19:56&p=1111111111&date=06.09.10&max=10&rt=1&&\">\n" //
|
||||
+ "<span class=\"bold\">CNL 450</span>\n" //
|
||||
+ "</a>\n" //
|
||||
|
@ -102,12 +111,15 @@ public class BahnProviderTest
|
|||
+ "Paris Est\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>");
|
||||
|
||||
assertNotNull(m.group(6)); // message
|
||||
assertNotNull(m.group(7)); // position
|
||||
}
|
||||
|
||||
@Test
|
||||
public void departureWithWeirdMessage()
|
||||
{
|
||||
assertFineDepartures("" //
|
||||
final Matcher m = assertFineDepartures("" //
|
||||
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/760983/402261/557174/24926/80/si=808093&bt=dep&ti=02:41&pt=02:41&p=1111111111&date=06.09.10&max=10&rt=1&&\">\n" //
|
||||
+ "<span class=\"bold\">ICE 609</span>\n" //
|
||||
+ "</a>\n" //
|
||||
|
@ -115,6 +127,23 @@ public class BahnProviderTest
|
|||
+ "Basel SBB\n" //
|
||||
+ "<br />\n" //
|
||||
+ "<span class=\"bold\">04:52</span> k.A., Gl. 3");
|
||||
|
||||
assertNotNull(m.group(7)); // position
|
||||
}
|
||||
|
||||
@Test
|
||||
public void departureWithMultipleMessages()
|
||||
{
|
||||
final Matcher m = assertFineDepartures("" //
|
||||
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/208035/206616/13568/62563/80/si=624141&bt=dep&ti=09:34&pt=09:34&p=1111111111&date=08.09.10&max=10&rt=1&&\">\n" //
|
||||
+ "<span class=\"bold\">S 1</span>\n" //
|
||||
+ "</a>\n" //
|
||||
+ ">>\n" //
|
||||
+ "München Ost\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>");
|
||||
|
||||
assertNotNull(m.group(6)); // message
|
||||
}
|
||||
|
||||
private void assertFineConnectionDetails(String s)
|
||||
|
@ -125,16 +154,17 @@ public class BahnProviderTest
|
|||
// ParserUtils.printGroups(m);
|
||||
}
|
||||
|
||||
private void assertFineDepartures(String s)
|
||||
private Matcher assertFineDepartures(String s)
|
||||
{
|
||||
Matcher m = BahnProvider.P_DEPARTURES_FINE.matcher(s);
|
||||
assertTrue(m.matches());
|
||||
|
||||
// ParserUtils.printGroups(m);
|
||||
ParserUtils.printGroups(m);
|
||||
|
||||
assertNotNull(m.group(1)); // line
|
||||
assertNotNull(m.group(2)); // destination
|
||||
assertNotNull(m.group(3)); // time
|
||||
assertNotNull(m.group(7)); // departure
|
||||
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue