mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-18 16:29:51 +00:00
extract nearby station scanning to hafas superclass
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@221 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
f7a6b7497f
commit
868a7bbc05
10 changed files with 198 additions and 119 deletions
|
@ -35,7 +35,7 @@ import de.schildbach.pte.QueryDeparturesResult.Status;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class SbbProvider implements NetworkProvider
|
||||
public class SbbProvider extends AbstractHafasProvider
|
||||
{
|
||||
public static final String NETWORK_ID = "fahrplan.sbb.ch";
|
||||
|
||||
|
@ -78,46 +78,12 @@ public class SbbProvider implements NetworkProvider
|
|||
return results;
|
||||
}
|
||||
|
||||
private final static String NEARBY_URI = "http://fahrplan.sbb.ch/bin/bhftafel.exe/dn?input=%d&distance=50&near=Anzeigen";
|
||||
private final static Pattern P_NEARBY_COARSE = Pattern.compile("<tr class=\"zebra-row-\\d\">(.*?)</tr>", Pattern.DOTALL);
|
||||
private final static Pattern P_NEARBY_FINE = Pattern.compile(".*?&REQMapRoute0\\.Location0\\.X=(-?\\d+)&REQMapRoute0\\.Location0\\.Y=(-?\\d+)"
|
||||
+ "&REQMapRoute0\\.Location0\\.Name=(.*?)&sturl=.*?dn\\?input=(\\d+).*?", Pattern.DOTALL);
|
||||
private final static String NEARBY_URI = "http://fahrplan.sbb.ch/bin/bhftafel.exe/dn?input=%s&distance=50&near=Anzeigen";
|
||||
|
||||
public List<Station> nearbyStations(final String stationId, final int lat, final int lon, final int maxDistance, final int maxStations)
|
||||
throws IOException
|
||||
@Override
|
||||
protected String nearbyStationUri(final String stationId)
|
||||
{
|
||||
if (stationId == null)
|
||||
throw new IllegalArgumentException("stationId must be given");
|
||||
|
||||
final List<Station> stations = new ArrayList<Station>();
|
||||
|
||||
final String uri = String.format(NEARBY_URI, stationId);
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
final Matcher mCoarse = P_NEARBY_COARSE.matcher(page);
|
||||
while (mCoarse.find())
|
||||
{
|
||||
final Matcher mFine = P_NEARBY_FINE.matcher(mCoarse.group(1));
|
||||
if (mFine.matches())
|
||||
{
|
||||
final int parsedLon = Integer.parseInt(mFine.group(1));
|
||||
final int parsedLat = Integer.parseInt(mFine.group(2));
|
||||
final String parsedName = ParserUtils.resolveEntities(mFine.group(3));
|
||||
final int parsedId = Integer.parseInt(mFine.group(4));
|
||||
|
||||
final Station station = new Station(parsedId, parsedName, parsedLat, parsedLon, 0, null, null);
|
||||
stations.add(station);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("cannot parse '" + mCoarse.group(1) + "' on " + uri);
|
||||
}
|
||||
}
|
||||
|
||||
if (maxStations == 0 || maxStations >= stations.size())
|
||||
return stations;
|
||||
else
|
||||
return stations.subList(0, maxStations);
|
||||
return String.format(NEARBY_URI, stationId);
|
||||
}
|
||||
|
||||
public StationLocationResult stationLocation(final String stationId) throws IOException
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue