Added configuration
This commit is contained in:
parent
67866265ba
commit
342a6c6db3
6 changed files with 146 additions and 15 deletions
|
@ -17,11 +17,13 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
public class Main {
|
||||
private static final HashMap<String, Integer> data = new HashMap<>();
|
||||
public static Settings conf;
|
||||
static OebbCheck check = new OebbCheck();
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
conf = Settings.getInstance();
|
||||
refresh();
|
||||
HttpServer server = HttpServer.create(new InetSocketAddress(8111), 0);
|
||||
HttpServer server = HttpServer.create(new InetSocketAddress(conf.getInt("port")), 0);
|
||||
server.createContext("/oebbapi", new OebbHandler());
|
||||
server.setExecutor(null); // creates a default executor
|
||||
server.start();
|
||||
|
@ -34,15 +36,15 @@ public class Main {
|
|||
}
|
||||
};
|
||||
try (ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor()) {
|
||||
service.scheduleAtFixedRate(task, 60, 60, TimeUnit.SECONDS);
|
||||
service.scheduleAtFixedRate(task, 60, conf.getInt("refreshTime"), TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
private static void refresh() throws IOException {
|
||||
data.put("06:16",check.getStatus("1250201","6:16", "Freilassing (Oberbayern)","S 3"));
|
||||
data.put("06:29",check.getStatus("1250201","6:29", "Salzburg Hbf","REX 3"));
|
||||
data.put("06:50",check.getStatus("8100002","6:50", "Freilassing (Oberbayern)","REX 5052"));
|
||||
data.put("06:39",check.getStatus("1250201","6:39", "Freilassing (Oberbayern)","R 3"));
|
||||
data.put(conf.getString("monitors.monitor1.DepartureTime"),check.getStatus(conf.getString("monitors.monitor1.Station"),conf.getString("monitors.monitor1.DepartureTime"), conf.getString("monitors.monitor1.FinalStop"),conf.getString("monitors.monitor1.TrainType")));
|
||||
data.put(conf.getString("monitors.monitor2.DepartureTime"),check.getStatus(conf.getString("monitors.monitor2.Station"),conf.getString("monitors.monitor2.DepartureTime"), conf.getString("monitors.monitor2.FinalStop"),conf.getString("monitors.monitor2.TrainType")));
|
||||
data.put(conf.getString("monitors.monitor3.DepartureTime"),check.getStatus(conf.getString("monitors.monitor3.Station"),conf.getString("monitors.monitor3.DepartureTime"), conf.getString("monitors.monitor3.FinalStop"),conf.getString("monitors.monitor3.TrainType")));
|
||||
data.put(conf.getString("monitors.monitor4.DepartureTime"),check.getStatus(conf.getString("monitors.monitor4.Station"),conf.getString("monitors.monitor4.DepartureTime"), conf.getString("monitors.monitor4.FinalStop"),conf.getString("monitors.monitor4.TrainType")));
|
||||
}
|
||||
|
||||
static class OebbHandler implements HttpHandler {
|
||||
|
@ -73,30 +75,30 @@ public class Main {
|
|||
dat.put(monitor1);
|
||||
|
||||
JSONObject monitor2 = new JSONObject();
|
||||
monitor2.put("label","S3 - 06:16");
|
||||
monitor2.put("label",conf.getString("monitors.monitor1.Title"));
|
||||
monitor2.put("labelColor","green");
|
||||
int zug1 = data.get("06:16");
|
||||
int zug1 = data.get(conf.getString("monitors.monitor1.DepartureTime"));
|
||||
makeLabel(monitor2, zug1);
|
||||
dat.put(monitor2);
|
||||
|
||||
JSONObject monitor3 = new JSONObject();
|
||||
monitor3.put("label","REX3 - 06:29");
|
||||
monitor3.put("label",conf.getString("monitors.monitor2.Title"));
|
||||
monitor3.put("labelColor","green");
|
||||
int zug2 = data.get("06:29");
|
||||
int zug2 = data.get(conf.getString("monitors.monitor2.DepartureTime"));
|
||||
makeLabel(monitor3, zug2);
|
||||
dat.put(monitor3);
|
||||
|
||||
JSONObject monitor4 = new JSONObject();
|
||||
monitor4.put("label","REX5052 - 06:50");
|
||||
monitor4.put("label",conf.getString("monitors.monitor3.Title"));
|
||||
monitor4.put("labelColor","green");
|
||||
int zug3 = data.get("06:50");
|
||||
int zug3 = data.get(conf.getString("monitors.monitor3.DepartureTime"));
|
||||
makeLabel(monitor4, zug3);
|
||||
dat.put(monitor4);
|
||||
|
||||
JSONObject monitor5 = new JSONObject();
|
||||
monitor5.put("label","R3 - 06:39");
|
||||
monitor5.put("label",conf.getString("monitors.monitor4.Title"));
|
||||
monitor5.put("labelColor","green");
|
||||
int zug4 = data.get("06:39");
|
||||
int zug4 = data.get(conf.getString("monitors.monitor4.DepartureTime"));
|
||||
makeLabel(monitor5, zug4);
|
||||
dat.put(monitor5);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue