mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-13 08:10:46 +00:00
separation in departures query url construction and query itself
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@9 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
1018c942de
commit
d416fd35b0
6 changed files with 64 additions and 44 deletions
|
@ -394,11 +394,16 @@ public final class BahnProvider implements NetworkProvider
|
|||
}
|
||||
}
|
||||
|
||||
private static final String DEPARTURE_URL = "http://mobile.bahn.de/bin/mobil/bhftafel.exe/dox?start=&maxJourneys=20&boardType=Abfahrt&productsFilter=1111111111000000&input=";
|
||||
|
||||
public String getDeparturesUri(String stationId)
|
||||
public String departuresQueryUri(final String stationId, final int maxDepartures)
|
||||
{
|
||||
return DEPARTURE_URL + stationId;
|
||||
final StringBuilder uri = new StringBuilder();
|
||||
uri.append("http://mobile.bahn.de/bin/mobil/bhftafel.exe/dox");
|
||||
uri.append("?start=");
|
||||
uri.append("&maxJourneys=").append(maxDepartures);
|
||||
uri.append("&boardType=Abfahrt");
|
||||
uri.append("&productsFilter=1111111111000000");
|
||||
uri.append("&input=").append(stationId);
|
||||
return uri.toString();
|
||||
}
|
||||
|
||||
private static final Pattern P_DEPARTURES_HEAD = Pattern.compile(".*<div class=\"haupt rline\">.*?"
|
||||
|
@ -409,9 +414,9 @@ public final class BahnProvider implements NetworkProvider
|
|||
private static final Pattern P_DEPARTURES_FINE = Pattern.compile(".*?<span class=\"bold\">(.*?)</span>.*?"
|
||||
+ ">>\\n?\\s*(.+?)\\s*\\n?<br />\\n?<span class=\"bold\">(\\d+:\\d+)</span>.*?", Pattern.DOTALL);
|
||||
|
||||
public GetDeparturesResult getDepartures(final String stationId, final Product[] products, final int maxDepartures) throws IOException
|
||||
public QueryDeparturesResult queryDepartures(final String uri, final Product[] products, final int maxDepartures) throws IOException
|
||||
{
|
||||
final CharSequence page = ParserUtils.scrape(getDeparturesUri(stationId));
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
// parse page
|
||||
final Matcher mHead = P_DEPARTURES_HEAD.matcher(page);
|
||||
|
@ -435,15 +440,15 @@ public final class BahnProvider implements NetworkProvider
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("cannot parse '" + mDepCoarse.group(1) + "' on " + stationId);
|
||||
throw new IllegalArgumentException("cannot parse '" + mDepCoarse.group(1) + "' on " + uri);
|
||||
}
|
||||
}
|
||||
|
||||
return new GetDeparturesResult(location, currentTime, departures);
|
||||
return new QueryDeparturesResult(location, currentTime, departures);
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetDeparturesResult.NO_INFO;
|
||||
return QueryDeparturesResult.NO_INFO;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -456,7 +456,7 @@ public class MvvProvider implements NetworkProvider
|
|||
|
||||
private static final String DEPARTURE_URL = "http://efa.mvv-muenchen.de/mobile/XSLT_DM_REQUEST?typeInfo_dm=stopID&mode=direct&nameInfo_dm=";
|
||||
|
||||
public String getDeparturesUri(final String stationId)
|
||||
public String departuresQueryUri(final String stationId, final int maxDepartures)
|
||||
{
|
||||
return DEPARTURE_URL + stationId;
|
||||
}
|
||||
|
@ -473,9 +473,9 @@ public class MvvProvider implements NetworkProvider
|
|||
+ "<br />\\s*(.*?)\\s*<br />.*?" // destination
|
||||
+ "</td>.*?", Pattern.DOTALL);
|
||||
|
||||
public GetDeparturesResult getDepartures(final String stationId, final Product[] products, final int maxDepartures) throws IOException
|
||||
public QueryDeparturesResult queryDepartures(final String uri, final Product[] products, final int maxDepartures) throws IOException
|
||||
{
|
||||
final CharSequence page = ParserUtils.scrape(getDeparturesUri(stationId));
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
final Matcher mHead = P_DEPARTURES_HEAD.matcher(page);
|
||||
if (mHead.matches())
|
||||
|
@ -508,15 +508,15 @@ public class MvvProvider implements NetworkProvider
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("cannot parse '" + mDepCoarse.group(1) + "' on " + stationId);
|
||||
throw new IllegalArgumentException("cannot parse '" + mDepCoarse.group(1) + "' on " + uri);
|
||||
}
|
||||
}
|
||||
|
||||
return new GetDeparturesResult(location, currentTime, departures);
|
||||
return new QueryDeparturesResult(location, currentTime, departures);
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetDeparturesResult.NO_INFO;
|
||||
return QueryDeparturesResult.NO_INFO;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -114,21 +114,23 @@ public interface NetworkProvider
|
|||
*
|
||||
* @param stationId
|
||||
* id of the station
|
||||
* @param maxDepartures
|
||||
* maximum number of departures to get or {@code 0}
|
||||
* @return uri for getting departures
|
||||
*/
|
||||
String getDeparturesUri(String stationId);
|
||||
String departuresQueryUri(String stationId, int maxDepartures);
|
||||
|
||||
/**
|
||||
* Get departures at a given station, probably live
|
||||
*
|
||||
* @param stationId
|
||||
* id of the station
|
||||
* @param queryUri
|
||||
* uri constructed by {@link NetworkProvider#departuresQueryUri}
|
||||
* @param products
|
||||
* products to consider or {@code null} to consider all products
|
||||
* products to filter or {@code null} to return all products
|
||||
* @param maxDepartures
|
||||
* maximum number of departures to get or {@code 0}
|
||||
* maximum number of departures to return or {@code 0}
|
||||
* @return result object containing the departures
|
||||
* @throws IOException
|
||||
*/
|
||||
GetDeparturesResult getDepartures(String stationId, Product[] products, int maxDepartures) throws IOException;
|
||||
QueryDeparturesResult queryDepartures(String queryUri, Product[] products, int maxDepartures) throws IOException;
|
||||
}
|
||||
|
|
|
@ -23,16 +23,16 @@ import java.util.List;
|
|||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public final class GetDeparturesResult
|
||||
public final class QueryDeparturesResult
|
||||
{
|
||||
public static final GetDeparturesResult NO_INFO = new GetDeparturesResult(null, null, null);
|
||||
public static final GetDeparturesResult SERVICE_DOWN = new GetDeparturesResult(null, null, null);
|
||||
public static final QueryDeparturesResult NO_INFO = new QueryDeparturesResult(null, null, null);
|
||||
public static final QueryDeparturesResult SERVICE_DOWN = new QueryDeparturesResult(null, null, null);
|
||||
|
||||
public final String location;
|
||||
public final Date currentTime;
|
||||
public final List<Departure> departures;
|
||||
|
||||
public GetDeparturesResult(final String location, final Date currentTime, final List<Departure> departures)
|
||||
public QueryDeparturesResult(final String location, final Date currentTime, final List<Departure> departures)
|
||||
{
|
||||
this.location = location;
|
||||
this.currentTime = currentTime;
|
|
@ -358,13 +358,21 @@ public class RmvProvider implements NetworkProvider
|
|||
}
|
||||
}
|
||||
|
||||
public String getDeparturesUri(final String stationId)
|
||||
public String departuresQueryUri(final String stationId, final int maxDepartures)
|
||||
{
|
||||
final DateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yy");
|
||||
final DateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm");
|
||||
final Date now = new Date();
|
||||
return "http://www.rmv.de/auskunft/bin/jp/stboard.exe/dox?input=" + stationId + "&boardType=dep&time=" + TIME_FORMAT.format(now) + "&date="
|
||||
+ DATE_FORMAT.format(now) + "&start=yes";
|
||||
|
||||
final StringBuilder uri = new StringBuilder();
|
||||
uri.append("http://www.rmv.de/auskunft/bin/jp/stboard.exe/dox");
|
||||
uri.append("?input=").append(stationId);
|
||||
uri.append("&boardType=dep");
|
||||
uri.append("&maxJourneys=").append(maxDepartures != 0 ? maxDepartures : 12);
|
||||
uri.append("&time=").append(TIME_FORMAT.format(now));
|
||||
uri.append("&date=").append(DATE_FORMAT.format(now));
|
||||
uri.append("&start=yes");
|
||||
return uri.toString();
|
||||
}
|
||||
|
||||
private static final Pattern P_DEPARTURES_HEAD = Pattern.compile(".*<p class=\"qs\">.*?" //
|
||||
|
@ -380,9 +388,9 @@ public class RmvProvider implements NetworkProvider
|
|||
+ "<b>(\\d+:\\d+)</b>.*?" // time
|
||||
+ "(?:Gl\\. (\\d+)<br />.*?)?", Pattern.DOTALL);
|
||||
|
||||
public GetDeparturesResult getDepartures(final String stationId, final Product[] products, final int maxDepartures) throws IOException
|
||||
public QueryDeparturesResult queryDepartures(final String uri, final Product[] products, final int maxDepartures) throws IOException
|
||||
{
|
||||
final CharSequence page = ParserUtils.scrape(getDeparturesUri(stationId));
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
// parse page
|
||||
final Matcher mHead = P_DEPARTURES_HEAD.matcher(page);
|
||||
|
@ -406,15 +414,15 @@ public class RmvProvider implements NetworkProvider
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("cannot parse '" + mDepCoarse.group(1) + "' on " + stationId);
|
||||
throw new IllegalArgumentException("cannot parse '" + mDepCoarse.group(1) + "' on " + uri);
|
||||
}
|
||||
}
|
||||
|
||||
return new GetDeparturesResult(location, currentTime, departures);
|
||||
return new QueryDeparturesResult(location, currentTime, departures);
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetDeparturesResult.NO_INFO;
|
||||
return QueryDeparturesResult.NO_INFO;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -352,13 +352,18 @@ public final class VbbProvider implements NetworkProvider
|
|||
return selected;
|
||||
}
|
||||
|
||||
private static final String DEPARTURE_URL_LIVE = "http://mobil.bvg.de/IstAbfahrtzeiten/index/mobil?input=";
|
||||
private static final String DEPARTURE_URL_PLAN = "http://mobil.bvg.de/Fahrinfo/bin/stboard.bin/dox/dox?boardType=dep&start=yes&maxJourneys=12&input=";
|
||||
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&";
|
||||
|
||||
public String getDeparturesUri(String stationId)
|
||||
public String departuresQueryUri(final String stationId, final int maxDepartures)
|
||||
{
|
||||
final boolean live = stationId.length() == 6;
|
||||
return live ? DEPARTURE_URL_LIVE + stationId : DEPARTURE_URL_PLAN + stationId;
|
||||
|
||||
final StringBuilder uri = new StringBuilder();
|
||||
uri.append(live ? DEPARTURE_URL_LIVE : DEPARTURE_URL_PLAN);
|
||||
uri.append("input=").append(stationId);
|
||||
uri.append("&maxJourneys=").append(maxDepartures != 0 ? maxDepartures : 12);
|
||||
return uri.toString();
|
||||
}
|
||||
|
||||
private static final Pattern P_DEPARTURES_HEAD = Pattern.compile(".*<strong>(.*?)</strong>.*Datum:(.*?)<br />.*", Pattern.DOTALL);
|
||||
|
@ -372,12 +377,12 @@ public final class VbbProvider implements NetworkProvider
|
|||
+ "<td>\\s*<a.*?>\\s*(.*?)\\s*</a>\\s*</td>", Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_SERVICE_DOWN = Pattern.compile("Wartungsarbeiten");
|
||||
|
||||
public GetDeparturesResult getDepartures(final String stationId, final Product[] products, final int maxDepartures) throws IOException
|
||||
public QueryDeparturesResult queryDepartures(final String uri, final Product[] products, final int maxDepartures) throws IOException
|
||||
{
|
||||
final CharSequence page = ParserUtils.scrape(getDeparturesUri(stationId));
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
if (P_DEPARTURES_SERVICE_DOWN.matcher(page).find())
|
||||
return GetDeparturesResult.SERVICE_DOWN;
|
||||
return QueryDeparturesResult.SERVICE_DOWN;
|
||||
|
||||
// parse page
|
||||
final Matcher mHead = P_DEPARTURES_HEAD.matcher(page);
|
||||
|
@ -391,7 +396,7 @@ public final class VbbProvider implements NetworkProvider
|
|||
final Matcher mDepCoarse = P_DEPARTURES_COARSE.matcher(page);
|
||||
while (mDepCoarse.find() && (maxDepartures == 0 || departures.size() < maxDepartures))
|
||||
{
|
||||
final boolean live = stationId.length() == 6;
|
||||
final boolean live = uri.contains("IstAbfahrtzeiten");
|
||||
final Matcher mDepFine = (live ? P_DEPARTURES_LIVE_FINE : P_DEPARTURES_PLAN_FINE).matcher(mDepCoarse.group(1));
|
||||
if (mDepFine.matches())
|
||||
{
|
||||
|
@ -402,15 +407,15 @@ public final class VbbProvider implements NetworkProvider
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("cannot parse '" + mDepCoarse.group(1) + "' on " + stationId);
|
||||
throw new IllegalArgumentException("cannot parse '" + mDepCoarse.group(1) + "' on " + uri);
|
||||
}
|
||||
}
|
||||
|
||||
return new GetDeparturesResult(location, currentTime, departures);
|
||||
return new QueryDeparturesResult(location, currentTime, departures);
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetDeparturesResult.NO_INFO;
|
||||
return QueryDeparturesResult.NO_INFO;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue