mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 06:08:52 +00:00
adapt to Switzerland format changes for departures
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@289 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
ee22585482
commit
6a97e1c316
2 changed files with 31 additions and 15 deletions
|
@ -405,26 +405,26 @@ public class SbbProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
private static final Pattern P_DEPARTURES_HEAD_COARSE = Pattern.compile(".*?" //
|
private static final Pattern P_DEPARTURES_HEAD_COARSE = Pattern.compile(".*?" //
|
||||||
+ "(?:" //
|
+ "(?:" //
|
||||||
+ "<p class=\"qs\">\n(.+?)\n</p>.*?" // head
|
+ "<p class=\"querysummary\">\n(.*?)</p>\n" // head
|
||||||
+ "(?:(.+)|(an dieser Haltestelle keines)).*?" // departures
|
+ "(?:(.*?)|(an dieser Haltestelle keines))\n" // departures
|
||||||
+ "<p class=\"links\">\n(.+?)\n</p>" //
|
+ "<p class=\"link1\">\n(.*?)</p>\n" // footer
|
||||||
+ "|(Informationen zu)" // messages
|
+ "|(Informationen zu)" // messages
|
||||||
+ "|(Verbindung zum Server konnte leider nicht hergestellt werden|kann vom Server derzeit leider nicht bearbeitet werden)" // messages
|
+ "|(Verbindung zum Server konnte leider nicht hergestellt werden|kann vom Server derzeit leider nicht bearbeitet werden)" // messages
|
||||||
+ ").*?" //
|
+ ").*?" //
|
||||||
, Pattern.DOTALL);
|
, Pattern.DOTALL);
|
||||||
private static final Pattern P_DEPARTURES_HEAD_FINE = Pattern.compile("" //
|
private static final Pattern P_DEPARTURES_HEAD_FINE = Pattern.compile("" //
|
||||||
+ "<b>(.*?)</b><br />\n" // location
|
+ "<strong>([^<]*)</strong>(?:<br />)?\n" // location
|
||||||
+ "Abfahrt (\\d+:\\d+)\n" // time
|
+ "Abfahrt (\\d{1,2}:\\d{2})\n" // time
|
||||||
+ "Uhr, (\\d{2}\\.\\d{2}\\.\\d{2}).*?" // date
|
+ "Uhr, (\\d{2}\\.\\d{2}\\.\\d{2})\n" // date
|
||||||
+ "input=(\\d+).*?" // locationId
|
+ ".*?input=(\\d+)&.*?" // locationId
|
||||||
, Pattern.DOTALL);
|
, Pattern.DOTALL);
|
||||||
private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("<p class=\"sq\">\n(.+?)</p>", Pattern.DOTALL);
|
private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("<p class=\"(journey con_\\d+)\">\n(.*?)</p>", Pattern.DOTALL);
|
||||||
private static final Pattern P_DEPARTURES_FINE = Pattern.compile("" //
|
private static final Pattern P_DEPARTURES_FINE = Pattern.compile("" //
|
||||||
+ "<b>(.*?)</b>\n" // line
|
+ "<strong>(.*?)</strong>\n" // line
|
||||||
+ ">>\n" //
|
+ ">>\n" //
|
||||||
+ "(.*?)\n" // destination
|
+ "(.*?)\n" // destination
|
||||||
+ "<br />\n" //
|
+ "<br />\n" //
|
||||||
+ "<b>(\\d+:\\d+)</b>\n" // time
|
+ "<strong>(\\d+:\\d+)</strong>\n" // time
|
||||||
+ "(?:Gl\\. (" + ParserUtils.P_PLATFORM + ")\n)?" // position
|
+ "(?:Gl\\. (" + ParserUtils.P_PLATFORM + ")\n)?" // position
|
||||||
+ ".*?" //
|
+ ".*?" //
|
||||||
, Pattern.DOTALL);
|
, Pattern.DOTALL);
|
||||||
|
@ -445,8 +445,8 @@ public class SbbProvider extends AbstractHafasProvider
|
||||||
else if (mHeadCoarse.group(6) != null)
|
else if (mHeadCoarse.group(6) != null)
|
||||||
return new QueryDeparturesResult(uri, Status.SERVICE_DOWN);
|
return new QueryDeparturesResult(uri, Status.SERVICE_DOWN);
|
||||||
|
|
||||||
final String c = mHeadCoarse.group(1) + mHeadCoarse.group(4);
|
final String head = mHeadCoarse.group(1) + mHeadCoarse.group(4);
|
||||||
final Matcher mHeadFine = P_DEPARTURES_HEAD_FINE.matcher(c);
|
final Matcher mHeadFine = P_DEPARTURES_HEAD_FINE.matcher(head);
|
||||||
if (mHeadFine.matches())
|
if (mHeadFine.matches())
|
||||||
{
|
{
|
||||||
final String location = ParserUtils.resolveEntities(mHeadFine.group(1));
|
final String location = ParserUtils.resolveEntities(mHeadFine.group(1));
|
||||||
|
@ -454,11 +454,18 @@ public class SbbProvider extends AbstractHafasProvider
|
||||||
.parseTime(mHeadFine.group(2)));
|
.parseTime(mHeadFine.group(2)));
|
||||||
final int locationId = Integer.parseInt(mHeadFine.group(4));
|
final int locationId = Integer.parseInt(mHeadFine.group(4));
|
||||||
final List<Departure> departures = new ArrayList<Departure>(8);
|
final List<Departure> departures = new ArrayList<Departure>(8);
|
||||||
|
String oldZebra = null;
|
||||||
|
|
||||||
final Matcher mDepCoarse = P_DEPARTURES_COARSE.matcher(mHeadCoarse.group(2));
|
final Matcher mDepCoarse = P_DEPARTURES_COARSE.matcher(mHeadCoarse.group(2));
|
||||||
while (mDepCoarse.find())
|
while (mDepCoarse.find())
|
||||||
{
|
{
|
||||||
final Matcher mDepFine = P_DEPARTURES_FINE.matcher(mDepCoarse.group(1));
|
final String zebra = mDepCoarse.group(1);
|
||||||
|
if (oldZebra != null && zebra.equals(oldZebra))
|
||||||
|
throw new IllegalArgumentException("missed row? last:" + zebra);
|
||||||
|
else
|
||||||
|
oldZebra = zebra;
|
||||||
|
|
||||||
|
final Matcher mDepFine = P_DEPARTURES_FINE.matcher(mDepCoarse.group(2));
|
||||||
if (mDepFine.matches())
|
if (mDepFine.matches())
|
||||||
{
|
{
|
||||||
final String line = normalizeLine(ParserUtils.resolveEntities(mDepFine.group(1)));
|
final String line = normalizeLine(ParserUtils.resolveEntities(mDepFine.group(1)));
|
||||||
|
@ -492,7 +499,7 @@ public class SbbProvider extends AbstractHafasProvider
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("cannot parse '" + c + "' on " + uri);
|
throw new IllegalArgumentException("cannot parse '" + head + "' on " + uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -28,6 +28,7 @@ import de.schildbach.pte.dto.Location;
|
||||||
import de.schildbach.pte.dto.LocationType;
|
import de.schildbach.pte.dto.LocationType;
|
||||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
import de.schildbach.pte.dto.QueryConnectionsResult;
|
import de.schildbach.pte.dto.QueryConnectionsResult;
|
||||||
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andreas Schildbach
|
* @author Andreas Schildbach
|
||||||
|
@ -42,7 +43,15 @@ public class SbbProviderLiveTest
|
||||||
{
|
{
|
||||||
final NearbyStationsResult result = provider.nearbyStations("8500010", 0, 0, 0, 0);
|
final NearbyStationsResult result = provider.nearbyStations("8500010", 0, 0, 0, 0);
|
||||||
|
|
||||||
System.out.println(result.stations.size() + " " + result.stations);
|
System.out.println(result.status + " " + result.stations.size() + " " + result.stations);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void queryDepartures() throws Exception
|
||||||
|
{
|
||||||
|
final QueryDeparturesResult result = provider.queryDepartures(provider.departuresQueryUri("8500010", 0));
|
||||||
|
|
||||||
|
System.out.println(result.status + " " + result.departures.size() + " " + result.departures);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue