Cleanup
This commit is contained in:
parent
24c4e622e1
commit
5565fd2201
2 changed files with 32 additions and 30 deletions
|
@ -11,14 +11,12 @@ import java.io.OutputStream;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
private static final HashMap<String, Integer> data = new HashMap<String, Integer>();
|
private static final HashMap<String, Integer> data = new HashMap<>();
|
||||||
static OebbCheck check = new OebbCheck();
|
static OebbCheck check = new OebbCheck();
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
@ -28,14 +26,11 @@ public class Main {
|
||||||
server.setExecutor(null); // creates a default executor
|
server.setExecutor(null); // creates a default executor
|
||||||
server.start();
|
server.start();
|
||||||
|
|
||||||
Runnable task = new Runnable() {
|
Runnable task = () -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
refresh();
|
||||||
try {
|
} catch (IOException e) {
|
||||||
refresh();
|
throw new RuntimeException(e);
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
try (ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor()) {
|
try (ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor()) {
|
||||||
|
|
|
@ -7,9 +7,9 @@ import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
public class OebbCheck {
|
public class OebbCheck {
|
||||||
|
|
||||||
|
@ -25,26 +25,16 @@ public class OebbCheck {
|
||||||
9999 means the Train has been cancelled
|
9999 means the Train has been cancelled
|
||||||
*/
|
*/
|
||||||
public int getStatus(String Station, String Time, String FinalStop, String TrainType) throws IOException {
|
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");
|
JSONArray journeys;
|
||||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
try {
|
||||||
con.setRequestMethod("GET");
|
journeys = getData(Station, Time);
|
||||||
BufferedReader in = new BufferedReader(
|
} catch (URISyntaxException e) {
|
||||||
new InputStreamReader(con.getInputStream()));
|
throw new RuntimeException(e);
|
||||||
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) {
|
for (Object journey : journeys) {
|
||||||
JSONObject jour = (JSONObject) journey;
|
JSONObject jour = (JSONObject) journey;
|
||||||
if(jour.get("st").equals(FinalStop)){
|
if(jour.get("st").equals(FinalStop) && jour.get("pr").equals(TrainType)){
|
||||||
|
if(jour.get("rt") instanceof JSONObject data) {
|
||||||
if(jour.get("rt") instanceof JSONObject) {
|
|
||||||
JSONObject data = (JSONObject) jour.get("rt");
|
|
||||||
if (data.get("status").equals("Ausfall")) {
|
if (data.get("status").equals("Ausfall")) {
|
||||||
return 9999;
|
return 9999;
|
||||||
} else {
|
} else {
|
||||||
|
@ -57,4 +47,21 @@ public class OebbCheck {
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static JSONArray getData(String Station, String Time) throws IOException, URISyntaxException {
|
||||||
|
URL url = new URI("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").toURL();
|
||||||
|
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||||
|
con.setRequestMethod("GET");
|
||||||
|
BufferedReader in = new BufferedReader(
|
||||||
|
new InputStreamReader(con.getInputStream()));
|
||||||
|
String inputLine;
|
||||||
|
StringBuilder content = new StringBuilder();
|
||||||
|
while ((inputLine = in.readLine()) != null) {
|
||||||
|
content.append(inputLine);
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
String sub = content.substring(14);
|
||||||
|
JSONObject jo = new JSONObject(sub);
|
||||||
|
return jo.getJSONArray("journey");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue