diff --git a/pom.xml b/pom.xml index 817d2b4..6e285ea 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ dev.katsute mta-information-site - 1.6.0 + 1.10.0 UTF-8 @@ -24,6 +24,18 @@ + + org.apache.maven.plugins + maven-jar-plugin + 3.3.0 + + + default-jar + none + + + + org.apache.maven.plugins maven-assembly-plugin @@ -40,7 +52,7 @@ jar-with-dependencies - ${artifactId} + ${project.artifactId} false diff --git a/src/main/java/dev/katsute/mis/JsonBuilder.java b/src/main/java/dev/katsute/mis/JsonBuilder.java index 7f8d37b..c888f1b 100644 --- a/src/main/java/dev/katsute/mis/JsonBuilder.java +++ b/src/main/java/dev/katsute/mis/JsonBuilder.java @@ -41,8 +41,8 @@ public final JsonBuilder set(final String key, final String object){ return append(key, object == null ? null : '"' + sanitize(object) + '"'); } - public final JsonBuilder set(final String key, final JsonBuilder obj){ - return append(key, obj.build()); + public final JsonBuilder set(final String key, final JsonBuilder object){ + return append(key, object.build()); } public final JsonBuilder set(final String key, final String[] strings){ @@ -52,9 +52,9 @@ public final JsonBuilder set(final String key, final String[] strings){ return append(key, '[' + String.join(", ", buf) + ']'); } - public final JsonBuilder set(final String key, final List objs){ + public final JsonBuilder set(final String key, final List objects){ final List buf = new ArrayList<>(); - for(final JsonBuilder obj : objs) + for(final JsonBuilder obj : objects) buf.add(obj.build()); return append(key, '[' + String.join(", ", buf) + ']'); } diff --git a/src/main/java/dev/katsute/mis/Main.java b/src/main/java/dev/katsute/mis/Main.java index 24e726c..e41f4ca 100644 --- a/src/main/java/dev/katsute/mis/Main.java +++ b/src/main/java/dev/katsute/mis/Main.java @@ -30,10 +30,6 @@ final class Main { - private static SimpleHttpServer server = null; - - private static MTA mta; - public static void main(String[] args) throws Throwable { System.out.println("Checking tokens"); // read tokens @@ -52,7 +48,7 @@ public static void main(String[] args) throws Throwable { } System.out.println("Initializing MTA"); // initialize MTA - mta = MTA.create( + final MTA mta = MTA.create( busToken, subwayToken, DataResource.create(DataResourceType.Bus_Bronx, new File("google_transit_bronx.zip")), @@ -66,7 +62,7 @@ public static void main(String[] args) throws Throwable { System.out.println("Initializing server"); // initialize server { - server = SimpleHttpServer.create(8080); + final SimpleHttpServer server = SimpleHttpServer.create(8080); server.setExecutor(Executors.newCachedThreadPool()); final FileHandler handler = new MimeFileHandler(); diff --git a/src/main/java/dev/katsute/mis/RequestHandler.java b/src/main/java/dev/katsute/mis/RequestHandler.java index 883a851..f100761 100644 --- a/src/main/java/dev/katsute/mis/RequestHandler.java +++ b/src/main/java/dev/katsute/mis/RequestHandler.java @@ -163,11 +163,18 @@ public final void handle(final SimpleHttpExchange exchange){ for(final Bus.Alert alert : alerts){ for(final TransitAlertPeriod per : alert.getActivePeriods()){ if(per.getStartEpochMillis() <= NOW && per.getEndEpochMillis() >= NOW){ + final String desc = alert.getDescription(); a.add(new JsonBuilder() .set("header", alert.getHeader()) - .set("description", alert.getDescription()) + .set("description", desc) .set("type", alert.getAlertType()) .set("effect", alert.getEffect()) + .set("slow", desc.contains("slow") || desc.contains("delay")) + .set("skip", desc.startsWith("no") || desc.contains("skips") || desc.contains("skipped")) + .set("construction", desc.contains("construction")) + .set("police", desc.contains("police") || desc.contains("nypd")) + .set("fire", desc.contains("fire") || desc.contains("fdny")) + .set("ems", desc.contains("ems")) ); break OUTER; } @@ -188,11 +195,18 @@ public final void handle(final SimpleHttpExchange exchange){ for(final Bus.Alert alert : r.getAlerts()){ for(final TransitAlertPeriod per : alert.getActivePeriods()){ if(per.getStartEpochMillis() <= NOW && per.getEndEpochMillis() >= NOW){ + final String desc = alert.getDescription(); a.add(new JsonBuilder() .set("header", alert.getHeader()) - .set("description", alert.getDescription()) + .set("description", desc) .set("type", alert.getAlertType()) .set("effect", alert.getEffect()) + .set("slow", desc.contains("slow") || desc.contains("delay")) + .set("skip", desc.startsWith("no") || desc.contains("skips") || desc.contains("skipped")) + .set("construction", desc.contains("construction")) + .set("police", desc.contains("police") || desc.contains("nypd")) + .set("fire", desc.contains("fire") || desc.contains("fdny")) + .set("ems", desc.contains("ems")) ); break OUTER; } @@ -272,11 +286,21 @@ public final void handle(final SimpleHttpExchange exchange){ for(final Subway.Alert alert : alerts){ for(final TransitAlertPeriod per : alert.getActivePeriods()){ if(per.getStartEpochMillis() <= NOW && per.getEndEpochMillis() >= NOW){ + final String desc = alert.getDescription().toLowerCase(); a.add(new JsonBuilder() .set("header", alert.getHeader()) .set("description", alert.getDescription()) .set("type", alert.getAlertType()) .set("effect", alert.getEffect()) + .set("slow", desc.contains("slow") || desc.contains("delay")) + .set("skip", desc.startsWith("no") || desc.contains("skips") || desc.contains("skipped")) + .set("local", desc.contains("local")) + .set("express", desc.contains("express")) + .set("shuttle", desc.contains("shuttle")) + .set("construction", desc.contains("construction")) + .set("police", desc.contains("police") || desc.contains("nypd")) + .set("fire", desc.contains("fire") || desc.contains("fdny")) + .set("ems", desc.contains("ems")) ); break OUTER; } @@ -297,11 +321,21 @@ public final void handle(final SimpleHttpExchange exchange){ for(final Subway.Alert alert : r.getAlerts()){ for(final TransitAlertPeriod per : alert.getActivePeriods()){ if(per.getStartEpochMillis() <= NOW && per.getEndEpochMillis() >= NOW){ + final String desc = alert.getDescription().toLowerCase(); a.add(new JsonBuilder() .set("header", alert.getHeader()) .set("description", alert.getDescription()) .set("type", alert.getAlertType()) .set("effect", alert.getEffect()) + .set("slow", desc.contains("slow") || desc.contains("delay")) + .set("skip", desc.startsWith("no") || desc.contains("skips") || desc.contains("skipped")) + .set("local", desc.contains("local")) + .set("express", desc.contains("express")) + .set("shuttle", desc.contains("shuttle")) + .set("construction", desc.contains("construction")) + .set("police", desc.contains("police") || desc.contains("nypd")) + .set("fire", desc.contains("fire") || desc.contains("fdny")) + .set("ems", desc.contains("ems")) ); break OUTER; } @@ -356,6 +390,4 @@ private static double distance(final double long1, final double lat1, final doub ); } - private static final int TODAY = Calendar.getInstance().get(Calendar.DAY_OF_YEAR); - }