mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-19 00:39:58 +00:00
split departures head parsing in coarse and fine
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@74 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
c0ecbe26f0
commit
187537ef7e
1 changed files with 47 additions and 37 deletions
|
@ -474,17 +474,19 @@ public class MvvProvider implements NetworkProvider
|
||||||
return DEPARTURE_URL + stationId;
|
return DEPARTURE_URL + stationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Pattern P_DEPARTURES_HEAD = Pattern.compile(".*Von:[\\xa0\\s]*</b>(.*?)<br />.*?" //
|
private static final Pattern P_DEPARTURES_HEAD_COARSE = Pattern.compile(".*?<body>(.*?Linie/Richtung.*?)</body>.*?", Pattern.DOTALL);
|
||||||
+ "Datum:[\\xa0\\s]*</b>\\w{2}\\.,\\s(\\d+)\\.\\s(\\w{3})\\.[\\xa0\\s]+(\\d{4})<br />.*", Pattern.DOTALL);
|
private static final Pattern P_DEPARTURES_HEAD_FINE = Pattern.compile(".*?" //
|
||||||
|
+ "Von:[\\xa0\\s]*</b>(.*?)<br />.*?" // location
|
||||||
|
+ "Datum:[\\xa0\\s]*</b>\\w{2}\\.,\\s(\\d+)\\.\\s(\\w{3})\\.[\\xa0\\s]+(\\d{4})<br />.*?" // date
|
||||||
|
, Pattern.DOTALL);
|
||||||
private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("<tr valign=\"top\" bgcolor=\"#\\w{6}\">(.+?)</tr>", Pattern.DOTALL);
|
private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("<tr valign=\"top\" bgcolor=\"#\\w{6}\">(.+?)</tr>", Pattern.DOTALL);
|
||||||
private static final Pattern P_DEPARTURES_FINE = Pattern.compile(".*?" //
|
private static final Pattern P_DEPARTURES_FINE = Pattern.compile(".*?" //
|
||||||
+ "<td>" //
|
|
||||||
+ "(?:[\\xa0\\s]*<font color=\"red\">[\\xa0\\s]*(\\d+)\\.(\\d+)\\.[\\xa0\\s]*</font>)?" // date
|
+ "(?:[\\xa0\\s]*<font color=\"red\">[\\xa0\\s]*(\\d+)\\.(\\d+)\\.[\\xa0\\s]*</font>)?" // date
|
||||||
+ "(\\d+):(\\d+)</td>.*?" // time
|
+ "(\\d+):(\\d+)</td>.*?" // time
|
||||||
+ "(?:<img src=\"images/means.*?\" alt=\"(.*?)\" />.*?)?" // product
|
+ "(?:<img src=\"images/means.*?\" alt=\"(.*?)\" />.*?)?" // product
|
||||||
+ "<td width=\"100\">\\s*([^<]*?)[\\xa0\\s]*(?:<a .*?</a>.*?)?" // line
|
+ "<td width=\"100\">\\s*([^<]*?)[\\xa0\\s]*(?:<a .*?</a>.*?)?" // line
|
||||||
+ "<br />\\s*(.*?)\\s*<br />.*?" // destination
|
+ "<br />\\s*(.*?)\\s*<br />.*?" // destination
|
||||||
+ "</td>.*?", Pattern.DOTALL);
|
, Pattern.DOTALL);
|
||||||
private static final Pattern P_DEPARTURES_URI_STATION_ID = Pattern.compile("nameInfo_dm=(\\d+)");
|
private static final Pattern P_DEPARTURES_URI_STATION_ID = Pattern.compile("nameInfo_dm=(\\d+)");
|
||||||
|
|
||||||
public QueryDeparturesResult queryDepartures(final String uri) throws IOException
|
public QueryDeparturesResult queryDepartures(final String uri) throws IOException
|
||||||
|
@ -496,11 +498,14 @@ public class MvvProvider implements NetworkProvider
|
||||||
throw new IllegalStateException(uri);
|
throw new IllegalStateException(uri);
|
||||||
final int stationId = Integer.parseInt(mStationId.group(1));
|
final int stationId = Integer.parseInt(mStationId.group(1));
|
||||||
|
|
||||||
final Matcher mHead = P_DEPARTURES_HEAD.matcher(page);
|
final Matcher mHeadCoarse = P_DEPARTURES_HEAD_COARSE.matcher(page);
|
||||||
if (mHead.matches())
|
if (mHeadCoarse.matches())
|
||||||
{
|
{
|
||||||
final String location = ParserUtils.resolveEntities(mHead.group(1));
|
final Matcher mHeadFine = P_DEPARTURES_HEAD_FINE.matcher(mHeadCoarse.group(1));
|
||||||
final Date currentTime = parseDate(mHead.group(2), mHead.group(3), mHead.group(4));
|
if (mHeadFine.matches())
|
||||||
|
{
|
||||||
|
final String location = ParserUtils.resolveEntities(mHeadFine.group(1));
|
||||||
|
final Date currentTime = parseDate(mHeadFine.group(2), mHeadFine.group(3), mHeadFine.group(4));
|
||||||
final List<Departure> departures = new ArrayList<Departure>(8);
|
final List<Departure> departures = new ArrayList<Departure>(8);
|
||||||
|
|
||||||
final Calendar calendar = new GregorianCalendar();
|
final Calendar calendar = new GregorianCalendar();
|
||||||
|
@ -534,6 +539,11 @@ public class MvvProvider implements NetworkProvider
|
||||||
return new QueryDeparturesResult(uri, stationId, location, currentTime, departures);
|
return new QueryDeparturesResult(uri, stationId, location, currentTime, departures);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("cannot parse '" + mHeadCoarse.group(1) + "' on " + uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
return QueryDeparturesResult.NO_INFO;
|
return QueryDeparturesResult.NO_INFO;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue