Made executor more resillient
This commit is contained in:
parent
19c2ab446f
commit
43d4e43d99
3 changed files with 84 additions and 18 deletions
|
@ -2,6 +2,8 @@ package be.jaud;
|
|||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
@ -12,7 +14,7 @@ import java.net.URISyntaxException;
|
|||
import java.net.URL;
|
||||
|
||||
public class OebbCheck {
|
||||
|
||||
public static final Logger LOG = LoggerFactory.getLogger(OebbCheck.class);
|
||||
public OebbCheck(){
|
||||
|
||||
}
|
||||
|
@ -24,26 +26,31 @@ public class OebbCheck {
|
|||
>0 is the delay in Minutes
|
||||
9999 means the Train has been cancelled
|
||||
*/
|
||||
public int getStatus(String Station, String Time, String FinalStop, String TrainType, String maxjourneys) throws IOException {
|
||||
JSONArray journeys;
|
||||
public int getStatus(String Station, String Time, String FinalStop, String TrainType, String maxjourneys) {
|
||||
JSONArray journeys = null;
|
||||
try {
|
||||
journeys = getData(Station, Time, maxjourneys);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
LOG.error("URISyntaxException: {}", e.toString());
|
||||
} catch (IOException e) {
|
||||
LOG.error("IOException: {}", e.toString());
|
||||
}
|
||||
for (Object journey : journeys) {
|
||||
JSONObject jour = (JSONObject) journey;
|
||||
if(jour.get("st").equals(FinalStop) && jour.get("pr").equals(TrainType)){
|
||||
if(jour.get("rt") instanceof JSONObject data) {
|
||||
if (data.get("status").equals("Ausfall")) {
|
||||
return 9999;
|
||||
if(journeys != null) {
|
||||
for (Object journey : journeys) {
|
||||
JSONObject jour = (JSONObject) journey;
|
||||
if (jour.get("st").equals(FinalStop) && jour.get("pr").equals(TrainType)) {
|
||||
if (jour.get("rt") instanceof JSONObject data) {
|
||||
if (data.get("status").equals("Ausfall")) {
|
||||
return 9999;
|
||||
} else {
|
||||
return data.getInt("dlm");
|
||||
}
|
||||
} else {
|
||||
return data.getInt("dlm");
|
||||
return 0;
|
||||
}
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue