mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-08 08:18:48 +00:00
use format for building uri
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@443 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
8393f75f60
commit
e70bf5064d
2 changed files with 23 additions and 3 deletions
|
@ -78,7 +78,7 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String AUTOCOMPLETE_NAME_URL = "http://mobil.bvg.de/Fahrinfo/bin/stboard.bin/dox/dox?input=";
|
private static final String AUTOCOMPLETE_NAME_URL = "http://mobil.bvg.de/Fahrinfo/bin/stboard.bin/dox/dox?input=%s";
|
||||||
private static final Pattern P_SINGLE_NAME = Pattern.compile(".*?Haltestelleninfo.*?<strong>(.*?)</strong>.*?input=(\\d+)&.*?", Pattern.DOTALL);
|
private static final Pattern P_SINGLE_NAME = Pattern.compile(".*?Haltestelleninfo.*?<strong>(.*?)</strong>.*?input=(\\d+)&.*?", Pattern.DOTALL);
|
||||||
private static final Pattern P_MULTI_NAME = Pattern.compile("<a href=\\\"/Fahrinfo/bin/stboard\\.bin/dox.*?input=(\\d+)&.*?\">\\s*(.*?)\\s*</a>",
|
private static final Pattern P_MULTI_NAME = Pattern.compile("<a href=\\\"/Fahrinfo/bin/stboard\\.bin/dox.*?input=(\\d+)&.*?\">\\s*(.*?)\\s*</a>",
|
||||||
Pattern.DOTALL);
|
Pattern.DOTALL);
|
||||||
|
@ -88,7 +88,8 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
{
|
{
|
||||||
final List<Location> results = new ArrayList<Location>();
|
final List<Location> results = new ArrayList<Location>();
|
||||||
|
|
||||||
final CharSequence page = ParserUtils.scrape(AUTOCOMPLETE_NAME_URL + ParserUtils.urlEncode(constraint.toString()));
|
final String uri = String.format(AUTOCOMPLETE_NAME_URL, ParserUtils.urlEncode(constraint.toString()));
|
||||||
|
final CharSequence page = ParserUtils.scrape(uri);
|
||||||
|
|
||||||
final Matcher mSingle = P_SINGLE_NAME.matcher(page);
|
final Matcher mSingle = P_SINGLE_NAME.matcher(page);
|
||||||
if (mSingle.matches())
|
if (mSingle.matches())
|
||||||
|
|
|
@ -17,9 +17,12 @@
|
||||||
|
|
||||||
package de.schildbach.pte.live;
|
package de.schildbach.pte.live;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import de.schildbach.pte.BvgProvider;
|
import de.schildbach.pte.BvgProvider;
|
||||||
|
import de.schildbach.pte.dto.Location;
|
||||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
|
|
||||||
|
@ -30,10 +33,26 @@ public class BvgProviderLiveTest
|
||||||
{
|
{
|
||||||
private BvgProvider provider = new BvgProvider();
|
private BvgProvider provider = new BvgProvider();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void autocompleteIncomplete() throws Exception
|
||||||
|
{
|
||||||
|
final List<Location> autocompletes = provider.autocompleteStations("nol");
|
||||||
|
|
||||||
|
list(autocompletes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void list(final List<Location> autocompletes)
|
||||||
|
{
|
||||||
|
System.out.print(autocompletes.size() + " ");
|
||||||
|
for (final Location autocomplete : autocompletes)
|
||||||
|
System.out.print(autocomplete.toDebugString() + " ");
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nearbyStation() throws Exception
|
public void nearbyStation() throws Exception
|
||||||
{
|
{
|
||||||
final NearbyStationsResult result = provider.nearbyStations("9415052", 0, 0, 0, 0);
|
final NearbyStationsResult result = provider.nearbyStations("9220302", 0, 0, 0, 0);
|
||||||
System.out.println(result.stations.size() + " " + result.stations);
|
System.out.println(result.stations.size() + " " + result.stations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue