diff --git a/src/de/schildbach/pte/BahnProvider.java b/src/de/schildbach/pte/BahnProvider.java index abaec0e5..1f23c02e 100644 --- a/src/de/schildbach/pte/BahnProvider.java +++ b/src/de/schildbach/pte/BahnProvider.java @@ -753,7 +753,7 @@ public final class BahnProvider implements NetworkProvider return "RSB" + number; if (type.equals("LT")) return "RLT" + number; - if (type.equals("CB")) // http://www.railfan.de/nebahn/morac.html + if (type.equals("CB")) // City Bahn Chemnitz return "RCB" + number; if (type.equals("SWE")) // SWEG return "RSWE" + number; diff --git a/src/de/schildbach/pte/OebbProvider.java b/src/de/schildbach/pte/OebbProvider.java index fda33008..5316fe42 100644 --- a/src/de/schildbach/pte/OebbProvider.java +++ b/src/de/schildbach/pte/OebbProvider.java @@ -473,7 +473,7 @@ public class OebbProvider implements NetworkProvider uri.append("&time=").append(TIME_FORMAT.format(now)); uri.append("&productsFilter=111111111111"); uri.append("&additionalTime=0"); - uri.append("&maxJourneys=20"); + uri.append("&maxJourneys=").append(maxDepartures != 0 ? maxDepartures : 20); uri.append("&start=yes"); uri.append("&selectDate=today"); uri.append("&monitor=1"); @@ -484,11 +484,20 @@ public class OebbProvider implements NetworkProvider return uri.toString(); } + private static final Pattern P_DEPARTURES_ERROR = Pattern.compile("(Verbindung zum Server konnte leider nicht hergestellt werden)"); + public QueryDeparturesResult queryDepartures(final String uri) throws IOException { // scrape page final String page = ParserUtils.scrape(uri).toString().substring(14); + final Matcher mError = P_DEPARTURES_ERROR.matcher(page); + if (mError.find()) + { + if (mError.group(1) != null) + return new QueryDeparturesResult(uri, Status.SERVICE_DOWN); + } + try { final JSONObject head = new JSONObject(page); @@ -516,8 +525,6 @@ public class OebbProvider implements NetworkProvider if (position != null) position = "Gl. " + position; final boolean rt = head.optBoolean("rt", false); - if (rt == true) - System.out.println("Realtime!!"); final String lineLink = departure.optString("tinfoline"); departures.add(new Departure(!rt ? time : null, rt ? time : null, line, line != null ? LINES.get(line.charAt(0)) : null, @@ -534,7 +541,10 @@ public class OebbProvider implements NetworkProvider } } - private static final Pattern P_NORMALIZE_LINE = Pattern.compile("([A-Za-zÄÖÜäöüßáàâéèêíìîóòôúùû-]+)[\\s]*(.*)"); + private static final Pattern P_NORMALIZE_LINE = Pattern.compile("([A-Za-zÄÖÜäöüßáàâéèêíìîóòôúùû/-]+)[\\s]*(.*)"); + private static final Pattern P_NORMALIZE_LINE_NUMBER = Pattern.compile("\\d{2,5}"); + private static final Pattern P_NORMALIZE_LINE_RUSSIA = Pattern.compile("\\d{1,3}[A-Z]{2}"); + private static final Pattern P_NORMALIZE_LINE_RUSSIA_INT = Pattern.compile("\\d{3}Y"); private static String normalizeLine(final String line) { @@ -548,12 +558,23 @@ public class OebbProvider implements NetworkProvider if (normalizedType != 0) return normalizedType + type + number; + // return '?' + strippedLine; throw new IllegalStateException("cannot normalize type " + type + " line " + line); } - else - { - throw new IllegalStateException("cannot normalize line " + line); - } + + if (line.length() == 0) + return "?"; + + if (P_NORMALIZE_LINE_RUSSIA.matcher(line).matches()) + return "R" + line; + + if (P_NORMALIZE_LINE_RUSSIA_INT.matcher(line).matches()) + return "I" + line; + + if (P_NORMALIZE_LINE_NUMBER.matcher(line).matches()) + return "?" + line; + + throw new IllegalStateException("cannot normalize line " + line); } private static String normalizeLine(final String type, final String line) @@ -565,8 +586,7 @@ public class OebbProvider implements NetworkProvider if (normalizedType != 0) return normalizedType + strippedLine; - return '?' + strippedLine; - // throw new IllegalStateException("cannot normalize type " + type + " line " + line); + throw new IllegalStateException("cannot normalize type " + type + " line " + line); } private static char normalizeType(final String type) @@ -585,48 +605,52 @@ public class OebbProvider implements NetworkProvider return 'I'; // if (ucType.equals("X")) // Interconnex // return 'I'; - // if (ucType.equals("EN")) // EuroNight - // return 'I'; - // if (ucType.equals("CNL")) // CityNightLine - // return 'I'; + if (ucType.equals("EN")) // EuroNight + return 'I'; + if (ucType.equals("CNL")) // CityNightLine + return 'I'; // if (ucType.equals("DNZ")) // Berlin-Saratov, Berlin-Moskva // return 'I'; // if (ucType.equals("INT")) // Rußland // return 'I'; - // if (ucType.equals("D")) // Rußland - // return 'I'; + if (ucType.equals("D")) // Rußland + return 'I'; // if (ucType.equals("RR")) // Finnland // return 'I'; - // if (ucType.equals("TLK")) // Tanie Linie Kolejowe, Polen - // return 'I'; + if (ucType.equals("TLK")) // Tanie Linie Kolejowe, Polen + return 'I'; // if (ucType.equals("EE")) // Rumänien // return 'I'; - // if (ucType.equals("SC")) // SuperCity, Tschechien - // return 'I'; - // if (ucType.equals("RJ")) // RailJet, Österreichische Bundesbahnen - // return 'I'; - // if (ucType.equals("EST")) // Eurostar Frankreich - // return 'I'; - // if (ucType.equals("ALS")) // Spanien - // return 'I'; - // if (ucType.equals("ARC")) // Spanien - // return 'I'; - // if (ucType.equals("TLG")) // Spanien, Madrid - // return 'I'; - // if (ucType.equals("HOT")) // Spanien, Nacht - // return 'I'; - // if (ucType.equals("AVE")) // Alta Velocidad Española, Spanien - // return 'I'; + if (ucType.equals("SC")) // SuperCity, Tschechien + return 'I'; + if (ucType.equals("RJ")) // RailJet, Österreichische Bundesbahnen + return 'I'; + if (ucType.equals("EST")) // Eurostar Frankreich + return 'I'; + if (ucType.equals("ALS")) // Spanien + return 'I'; + if (ucType.equals("ARC")) // Spanien + return 'I'; + if (ucType.equals("TLG")) // Spanien, Madrid + return 'I'; + if (ucType.equals("HOT")) // Spanien, Nacht + return 'I'; + if (ucType.equals("AVE")) // Alta Velocidad Española, Spanien + return 'I'; // if (ucType.equals("INZ")) // Schweden, Nacht // return 'I'; + if (ucType.equals("NZ")) // Schweden, Nacht, via JSON API + return 'I'; // if (ucType.equals("OZ")) // Schweden, Oeresundzug // return 'I'; // if (ucType.equals("X2")) // Schweden // return 'I'; - // if (ucType.equals("THA")) // Thalys - // return 'I'; - // if (ucType.equals("TGV")) // Train à Grande Vitesse - // return 'I'; + if (ucType.equals("X")) // Schweden, via JSON API + return 'I'; + if (ucType.equals("THA")) // Thalys + return 'I'; + if (ucType.equals("TGV")) // Train à Grande Vitesse + return 'I'; // if (ucType.equals("LYN")) // Dänemark // return 'I'; if (ucType.equals("ARZ")) // Frankreich, Nacht @@ -656,8 +680,8 @@ public class OebbProvider implements NetworkProvider return 'R'; // if (ucType.equals("ZUG")) // return 'R'; - // if (ucType.equals("EZ")) // Erlebniszug - // return 'R'; + if (ucType.equals("EZ")) // Erlebniszug + return 'R'; // if (ucType.equals("S2")) // Helsinki-Turku // return 'R'; if (ucType.equals("RB")) // RegionalBahn Deutschland @@ -666,49 +690,157 @@ public class OebbProvider implements NetworkProvider return 'R'; // if (ucType.equals("DPN")) // TODO nicht evtl. doch eher ne S-Bahn? // return 'R'; - // if (ucType.equals("VIA")) - // return 'R'; - // if (ucType.equals("PCC")) // Polen - // return 'R'; - // if (ucType.equals("KM")) // Polen - // return 'R'; - // if (ucType.equals("SKM")) // Polen - // return 'R'; - // if (ucType.equals("SKW")) // Polen - // return 'R'; - // if (ucType.equals("WKD")) // Warszawska Kolej Dojazdowa, Polen - // return 'R'; - // if (ucType.equals("IR")) // Polen - // return 'R'; - // if (ucType.equals("OS")) // Chop-Cierna nas Tisou - // return 'R'; - // if (ucType.equals("SP")) // Polen - // return 'R'; - // if (ucType.equals("EX")) // Polen - // return 'R'; - // if (ucType.equals("E")) // Budapest, Ungarn - // return 'R'; - // if (ucType.equals("IP")) // Ozd, Ungarn - // return 'R'; - // if (ucType.equals("ZR")) // Bratislava, Slovakai - // return 'R'; - // if (ucType.equals("CAT")) // Stockholm-Arlanda, Arlanda Express - // return 'R'; - // if (ucType.equals("RT")) // Deutschland - // return 'R'; - // if (ucType.equals("IRE")) // Interregio Express - // return 'R'; + if (ucType.equals("BRB")) // ABELLIO Rail, via JSON API + return 'R'; + if (ucType.equals("ABR")) // Bayerische Regiobahn, via JSON API + return 'R'; + if (ucType.equals("RTB")) // Rurtalbahn, via JSON API + return 'R'; + if (ucType.equals("VIA")) + return 'R'; + if (ucType.equals("PCC")) // Polen + return 'R'; + if (ucType.equals("KM")) // Polen + return 'R'; + if (ucType.equals("SKM")) // Polen + return 'R'; + if (ucType.equals("SKW")) // Polen + return 'R'; + if (ucType.equals("WKD")) // Warszawska Kolej Dojazdowa, Polen + return 'R'; + if (ucType.equals("IR")) // Polen + return 'R'; + if (ucType.equals("OS")) // Chop-Cierna nas Tisou + return 'R'; + if (ucType.equals("SP")) // Polen + return 'R'; + if (ucType.equals("EX")) // Polen + return 'R'; + if (ucType.equals("NEB")) // Kostrzyn-Berlin, via JSON API + return 'R'; + if (ucType.equals("E")) // Budapest, Ungarn + return 'R'; + if (ucType.equals("IP")) // Ozd, Ungarn + return 'R'; + if (ucType.equals("ZR")) // Bratislava, Slovakai + return 'R'; + if (ucType.equals("CAT")) // Stockholm-Arlanda, Arlanda Express + return 'R'; + if (ucType.equals("RT")) // Deutschland + return 'R'; + if (ucType.equals("IRE")) // Interregio Express + return 'R'; // if (ucType.equals("N")) // Frankreich, Tours // return 'R'; // if (ucType.equals("DPF")) // VX=Vogtland Express // return 'R'; + if (ucType.equals("VBG")) // Vogtlandbahn, via JSON API + return 'R'; + if (ucType.equals("SBE")) // Zittau-Seifhennersdorf, via JSON API + return 'R'; + if (ucType.equals("UBB")) // Usedomer Bäderbahn, via JSON API + return 'R'; + if (ucType.equals("HZL")) // Hohenzollerische Landesbahn, via JSON API + return 'R'; + if (ucType.equals("ME")) // metronom Eisenbahngesellschaft, via JSON API + return 'R'; + if (ucType.equals("MER")) // metronom regional, via JSON API + return 'R'; + if (ucType.equals("PEG")) // Prignitzer Eisenbahn, via JSON API + return 'R'; + if (ucType.equals("HLB")) // Hessische Landesbahn, via JSON API + return 'R'; + if (ucType.equals("NWB")) // NordWestBahn, via JSON API + return 'R'; + if (ucType.equals("VEN")) // Rhenus Veniro, via JSON API + return 'R'; + if (ucType.equals("BOB")) // Bayerische Oberlandbahn, via JSON API + return 'R'; + if (ucType.equals("SBB")) // Schweizerische Bundesbahnen, via JSON API + return 'R'; + if (ucType.equals("ERB")) // eurobahn (Keolis Deutschland), via JSON API + return 'R'; + if (ucType.equals("CAN")) // cantus Verkehrsgesellschaft, via JSON API + return 'R'; + if (ucType.equals("ALX")) // Arriva-Länderbahn-Express, via JSON API + return 'R'; + if (ucType.equals("VEC")) // vectus Verkehrsgesellschaft, via JSON API + return 'R'; + if (ucType.equals("OSB")) // Ortenau-S-Bahn, via JSON API + return 'R'; + if (ucType.equals("NOB")) // Nord-Ostsee-Bahn, via JSON API + return 'R'; + if (ucType.equals("MRB")) // Mitteldeutsche Regiobahn, via JSON API + return 'R'; + if (ucType.equals("WFB")) // Westfalenbahn, via JSON API + return 'R'; + if (ucType.equals("ARR")) // Ostfriesland, via JSON API + return 'R'; + if (ucType.equals("SHB")) // Schleswig-Holstein-Bahn, via JSON API + return 'R'; + if (ucType.equals("BLB")) // Berchtesgadener Land Bahn, via JSON API + return 'R'; + if (ucType.equals("AKN")) // AKN Eisenbahn AG, via JSON API + return 'R'; + if (ucType.equals("EVB")) // Eisenbahnen und Verkehrsbetriebe Elbe-Weser, via JSON API + return 'R'; + if (ucType.equals("EB")) // Erfurter Bahn, via JSON API + return 'R'; + if (ucType.equals("HTB")) // Hörseltalbahn, via JSON API + return 'R'; + if (ucType.equals("NBE")) // nordbahn, via JSON API + return 'R'; + if (ucType.equals("DAB")) // Daadetalbahn, via JSON API + return 'R'; + if (ucType.equals("HEX")) // Harz-Berlin-Express, Veolia, via JSON API + return 'R'; + if (ucType.equals("WEG")) // Württembergische Eisenbahn-Gesellschaft, via JSON API + return 'R'; + if (ucType.equals("RBG")) // Regental Bahnbetriebs GmbH, via JSON API + return 'R'; + if (ucType.equals("OE")) // Ostdeutsche Eisenbahn, via JSON API + return 'R'; + if (ucType.equals("CB")) // City Bahn Chemnitz, via JSON API + return 'R'; + if (ucType.equals("MR")) // Märkische Regionalbahn, via JSON API + return 'R'; + if (ucType.equals("OLA")) // Ostseeland Verkehr, via JSON API + return 'R'; + if (ucType.equals("VX")) // Vogtland Express, via JSON API + return 'R'; + if (ucType.equals("STB")) // Süd-Thüringen-Bahn, via JSON API + return 'R'; + if (ucType.equals("RNV")) // Rhein-Neckar-Verkehr GmbH, via JSON API + return 'R'; + if (ucType.equals("MBB")) // Mecklenburgische Bäderbahn Molli, via JSON API + return 'R'; + if (ucType.equals("HSB")) // Harzer Schmalspurbahnen, via JSON API + return 'R'; + if (ucType.equals("VE")) // Lutherstadt Wittenberg, via JSON API + return 'R'; + if (ucType.equals("PRE")) // Pressnitztalbahn, via JSON API + return 'R'; + if (ucType.equals("SDG")) // Sächsische Dampfeisenbahngesellschaft, via JSON API + return 'R'; + if (ucType.equals("SOE")) // Sächsisch-Oberlausitzer Eisenbahngesellschaft, via JSON API + return 'R'; + if (ucType.equals("FEG")) // Freiberger Eisenbahngesellschaft, via JSON API + return 'R'; + if (ucType.equals("NEG")) // Norddeutsche Eisenbahngesellschaft Niebüll, via JSON API + return 'R'; if (ucType.equals("S")) return 'S'; if (ucType.equals("RSB")) // Schnellbahn Wien return 'S'; - // if (ucType.equals("RER")) // Réseau Express Régional, Frankreich - // return 'S'; + if (ucType.equals("BSB")) // Breisgau S-Bahn, via JSON API + return 'S'; + if (ucType.equals("DPN")) // S3 Bad Reichenhall-Freilassing, via JSON API + return 'S'; + if (ucType.equals("SWE")) // Südwestdeutsche Verkehrs-AG, Ortenau-S-Bahn, via JSON API + return 'S'; + if (ucType.equals("RER")) // Réseau Express Régional, Frankreich + return 'S'; if (ucType.equals("U")) return 'U'; @@ -722,8 +854,8 @@ public class OebbProvider implements NetworkProvider if (ucType.equals("BUS")) return 'B'; - // if (ucType.equals("RFB")) - // return 'B'; + if (ucType.equals("RFB")) + return 'B'; // if (ucType.equals("OBU")) // return 'B'; if (ucType.equals("AST")) @@ -740,6 +872,10 @@ public class OebbProvider implements NetworkProvider // return 'B'; if (ucType.equals("BUSSV")) // via JSON API return 'B'; + if (ucType.equals("BUSLEOBE")) // Rufbus, via JSON API + return 'B'; + if (ucType.equals("BUSTN/TW")) // via JSON API + return 'B'; if (ucType.equals("O-B")) // Stadtbus, via JSON API return 'B'; @@ -747,12 +883,19 @@ public class OebbProvider implements NetworkProvider // return 'F'; // if (ucType.equals("AS")) // SyltShuttle // return 'F'; - // + if (ucType.equals("SCHIFF")) // via JSON API + return 'F'; + // if (ucType.equals("SB")) // return 'C'; - // if (ucType.equals("LIF")) - // return 'C'; - // + if (ucType.equals("LIF")) + return 'C'; + if (ucType.equals("SEILBAHN")) // via JSON API + return 'C'; + + if (ucType.equals("FLUG")) // via JSON API + return 'I'; + // if (ucType.equals("U70")) // U.K. // return '?'; // if (ucType.equals("R84"))