Initial commit
This commit is contained in:
commit
24c4e622e1
9 changed files with 410 additions and 0 deletions
60
src/main/java/be/jaud/OebbCheck.java
Normal file
60
src/main/java/be/jaud/OebbCheck.java
Normal file
|
@ -0,0 +1,60 @@
|
|||
package be.jaud;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class OebbCheck {
|
||||
|
||||
public OebbCheck(){
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the Delay in Minutes for a given StationID, Departure Time, final stop and Train type(i.e. REX 3, S 2....)
|
||||
Returns -1 if no connection was found
|
||||
Returns 0 for no delay
|
||||
>0 is the delay in Minutes
|
||||
9999 means the Train has been cancelled
|
||||
*/
|
||||
public int getStatus(String Station, String Time, String FinalStop, String TrainType) throws IOException {
|
||||
URL url = new URL("https://fahrplan.oebb.at/bin/stboard.exe/dn?L=vs_scotty.vs_liveticker&evaId=" + Station + "&boardType=dep&time="+Time+"&productsFilter=1011110111011&additionalTime=0&maxJourneys=1&outputMode=tickerDataOnly&start=yes&selectDate=today");
|
||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
BufferedReader in = new BufferedReader(
|
||||
new InputStreamReader(con.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuffer content = new StringBuffer();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
content.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
String sub = content.substring(14);
|
||||
JSONObject jo = new JSONObject(sub);
|
||||
JSONArray journeys = jo.getJSONArray("journey");
|
||||
for (Object journey : journeys) {
|
||||
JSONObject jour = (JSONObject) journey;
|
||||
if(jour.get("st").equals(FinalStop)){
|
||||
|
||||
if(jour.get("rt") instanceof JSONObject) {
|
||||
JSONObject data = (JSONObject) jour.get("rt");
|
||||
if (data.get("status").equals("Ausfall")) {
|
||||
return 9999;
|
||||
} else {
|
||||
return data.getInt("dlm");
|
||||
}
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue