mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 22:48:49 +00:00
parse additional message for Frankfurt
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@154 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
6f16898846
commit
7dfc244ce7
4 changed files with 48 additions and 28 deletions
|
@ -241,10 +241,28 @@ public final class ParserUtils
|
|||
}
|
||||
}
|
||||
|
||||
public static <T> T selectNotNull(final T... groups)
|
||||
{
|
||||
T selected = null;
|
||||
|
||||
for (final T group : groups)
|
||||
{
|
||||
if (group != null)
|
||||
{
|
||||
if (selected == null)
|
||||
selected = group;
|
||||
else
|
||||
throw new IllegalStateException("ambiguous");
|
||||
}
|
||||
}
|
||||
|
||||
return selected;
|
||||
}
|
||||
|
||||
public static String extractId(final String link)
|
||||
{
|
||||
return link.substring(link.length() - 10);
|
||||
}
|
||||
|
||||
|
||||
public static final String P_PLATFORM = "[\\wÄÖÜäöüßáàâéèêíìîóòôúùû\\. -/&#;]+?";
|
||||
}
|
||||
|
|
|
@ -460,8 +460,9 @@ public class RmvProvider implements NetworkProvider
|
|||
+ "<b>(\\d{1,2}:\\d{2})</b>\n" // plannedTime
|
||||
+ "(?:keine Prognose verfügbar\n)?" //
|
||||
+ "(?:<span class=\"red\">ca\\. (\\d{1,2}:\\d{2})</span>\n)?" // predictedTime
|
||||
+ "(?:<span class=\"red\">heute Gl\\. " + ParserUtils.P_PLATFORM + "</span><br />\n)?" // predictedPosition
|
||||
+ "(?:<span class=\"red\">heute (Gl\\. " + ParserUtils.P_PLATFORM + ")</span><br />\n)?" // predictedPosition
|
||||
+ "(?:(Gl\\. " + ParserUtils.P_PLATFORM + ")<br />\n)?" // position
|
||||
+ "(?:<span class=\"red\">([^>]*)</span>\n)?" // message
|
||||
+ "(?:<img src=\".+?\" alt=\"\" />\n<b>.+?</b>\n<br />\n)*" // (messages)
|
||||
, Pattern.DOTALL);
|
||||
|
||||
|
@ -495,18 +496,14 @@ public class RmvProvider implements NetworkProvider
|
|||
final Matcher mDepFine = P_DEPARTURES_FINE.matcher(mDepCoarse.group(1));
|
||||
if (mDepFine.matches())
|
||||
{
|
||||
// line
|
||||
final String line = normalizeLine(ParserUtils.resolveEntities(mDepFine.group(1)));
|
||||
|
||||
// destination
|
||||
final String destination = ParserUtils.resolveEntities(mDepFine.group(2));
|
||||
|
||||
// time
|
||||
final Calendar current = new GregorianCalendar();
|
||||
current.setTime(currentTime);
|
||||
final Calendar parsed = new GregorianCalendar();
|
||||
|
||||
// plannedTime
|
||||
parsed.setTime(ParserUtils.parseTime(mDepFine.group(3)));
|
||||
parsed.set(Calendar.YEAR, current.get(Calendar.YEAR));
|
||||
parsed.set(Calendar.MONTH, current.get(Calendar.MONTH));
|
||||
|
@ -515,7 +512,6 @@ public class RmvProvider implements NetworkProvider
|
|||
parsed.add(Calendar.DAY_OF_MONTH, 1);
|
||||
final Date plannedTime = parsed.getTime();
|
||||
|
||||
// predictedTime
|
||||
Date predictedTime = null;
|
||||
if (mDepFine.group(4) != null)
|
||||
{
|
||||
|
@ -528,8 +524,7 @@ public class RmvProvider implements NetworkProvider
|
|||
predictedTime = parsed.getTime();
|
||||
}
|
||||
|
||||
// position
|
||||
final String position = ParserUtils.resolveEntities(mDepFine.group(5));
|
||||
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,
|
||||
position, 0, destination, null);
|
||||
|
|
|
@ -454,7 +454,7 @@ public final class VbbProvider implements NetworkProvider
|
|||
{
|
||||
final int arrivalId = mDetFine.group(12) != null ? Integer.parseInt(mDetFine.group(12)) : 0;
|
||||
|
||||
final String arrival = ParserUtils.resolveEntities(selectNotNull(mDetFine.group(13), mDetFine.group(16), mDetFine.group(17)));
|
||||
final String arrival = ParserUtils.resolveEntities(ParserUtils.selectNotNull(mDetFine.group(13), mDetFine.group(16), mDetFine.group(17)));
|
||||
|
||||
final double arrivalLon = mDetFine.group(14) != null ? latLonToDouble(Integer.parseInt(mDetFine.group(14))) : 0;
|
||||
|
||||
|
@ -494,22 +494,6 @@ public final class VbbProvider implements NetworkProvider
|
|||
}
|
||||
}
|
||||
|
||||
private static String selectNotNull(final String... groups)
|
||||
{
|
||||
String selected = null;
|
||||
for (final String group : groups)
|
||||
{
|
||||
if (group != null)
|
||||
{
|
||||
if (selected == null)
|
||||
selected = group;
|
||||
else
|
||||
throw new IllegalStateException("ambiguous");
|
||||
}
|
||||
}
|
||||
return selected;
|
||||
}
|
||||
|
||||
private static final String DEPARTURE_URL_LIVE = "http://mobil.bvg.de/IstAbfahrtzeiten/index/mobil?";
|
||||
private static final String DEPARTURE_URL_PLAN = "http://mobil.bvg.de/Fahrinfo/bin/stboard.bin/dox/dox?boardType=dep&start=yes&";
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package de.schildbach.pte;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
|
@ -31,19 +32,41 @@ public class RmvProviderTest
|
|||
@Test
|
||||
public void departureWithNoPrognosisMessage()
|
||||
{
|
||||
assertFineDepartures("<b>Bus 42 </b>\n" //
|
||||
final Matcher m = assertFineDepartures("<b>Bus 42 </b>\n" //
|
||||
+ ">>\n" //
|
||||
+ "Frankfurt (Main) Enkheim\n" //
|
||||
+ "<br />\n" //
|
||||
+ "<b>20:21</b>\n" //
|
||||
+ "keine Prognose verfügbar\n" //
|
||||
+ "<span class=\"red\">heute Gl. Enkheim</span><br />\n");
|
||||
|
||||
assertNotNull(m.group(5)); // predictedPosition
|
||||
}
|
||||
|
||||
private void assertFineDepartures(String s)
|
||||
@Test
|
||||
public void departureWithMessage()
|
||||
{
|
||||
final Matcher m = assertFineDepartures("<b>Bus 274 </b>\n" //
|
||||
+ ">>\n" //
|
||||
+ "Bad Schwalbach Kurhaus\n" //
|
||||
+ "<br />\n" //
|
||||
+ "<b>15:47</b>\n" //
|
||||
+ "<span class=\"red\">Zug fällt aus</span>\n");
|
||||
|
||||
assertNotNull(m.group(7)); // message
|
||||
}
|
||||
|
||||
private Matcher assertFineDepartures(String s)
|
||||
{
|
||||
Matcher m = RmvProvider.P_DEPARTURES_FINE.matcher(s);
|
||||
assertTrue(m.matches());
|
||||
|
||||
// ParserUtils.printGroups(m);
|
||||
|
||||
assertNotNull(m.group(1)); // line
|
||||
assertNotNull(m.group(2)); // destination
|
||||
assertNotNull(m.group(3)); // time
|
||||
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue