25 Commits
Author SHA1 Message Date
JoeMolinelli 9c23c4f827 Format README.md for consistency and clarity 2026-09-27 20:47:36 -04:00
JoeMolinelli 27a70dc6f0 Update README.md 2026-09-27 20:47:01 -04:00
JoeMolinelli cc87e32278 Update pom.xml 2026-09-27 02:09:02 -04:00
JoeMolinelli 5923ef2043 Add files via upload 2026-09-27 02:08:37 -04:00
JoeMolinelli 5801b8ab41 Delete src/main directory 2026-09-27 02:07:49 -04:00
JoeMolinelli 76c51648f3 Update README.md 2026-09-27 02:07:38 -04:00
JoeMolinelli a3e5e81500 Add files via upload 2026-08-14 23:19:31 -04:00
JoeMolinelli a2791ddd91 Delete src directory 2026-08-14 23:19:08 -04:00
JoeMolinelli dbe9b0964d Update pom.xml 2026-08-14 23:18:55 -04:00
JoeMolinelli 742714fbac Add files via upload 2026-08-04 23:54:29 -04:00
JoeMolinelli a29f4d0829 Delete src directory 2026-08-04 23:54:09 -04:00
JoeMolinelli 02e0a7cf1f Update pom.xml 2026-08-04 23:53:58 -04:00
JoeMolinelli 5177d0fead Add files via upload 2026-08-04 19:50:46 -04:00
JoeMolinelli 1cc60fe38c Delete src directory 2026-08-04 19:50:26 -04:00
JoeMolinelli ea86c54d5a Update pom.xml 2026-08-04 19:40:14 -04:00
JoeMolinelli 35357d3082 Update pom.xml 2026-08-04 17:50:53 -04:00
JoeMolinelli a4f69d5b1b Add files via upload 2026-08-04 17:50:09 -04:00
JoeMolinelli 5cdc6af9dd Delete src directory 2026-08-04 17:49:40 -04:00
JoeMolinelli 1ecfc3c965 Add files via upload 2026-08-04 00:42:33 -04:00
JoeMolinelli 7396be94c9 Delete src directory 2026-08-04 00:42:08 -04:00
JoeMolinelli e501a99559 Update pom.xml 2026-08-04 00:41:46 -04:00
JoeMolinelli 604fedab47 Add files via upload 2026-08-04 00:41:27 -04:00
JoeMolinelli 8b50b3b60c Delete screenshots directory 2026-08-04 00:41:17 -04:00
JoeMolinelli 116a409b6d Add files via upload 2026-08-01 15:37:32 -04:00
JoeMolinelli 5eb6fade7f Delete src/main directory 2026-08-01 15:37:11 -04:00
22 changed files with 2053 additions and 1233 deletions

No files matched your search

+2 -12
View File
@@ -1,7 +1,7 @@
# WeatherSTAR 3000 Simulator # WeatherSTAR 3000 Simulator
WeatherSTAR 3000 Simulator in Java by Joe Molinelli/Mist Weather Media WeatherSTAR 3000 Simulator in Java by Joe Molinelli/Mist Weather Media
Compatible with Java 25+ Compatible with Java 8+
------------ ------------
![Current Conditions](/screenshots/currentconditions.png) ![Current Conditions](/screenshots/currentconditions.png)
@@ -11,9 +11,7 @@ Need support beyond the scope of this README? Have any questions? Feel free to j
Suggestions? Fixes you want to propose? Submit a Pull Request in the Pull Requests tab! Suggestions? Fixes you want to propose? Submit a Pull Request in the Pull Requests tab!
Either of the following methods can be used: ## Installation Instructions:
## Installation Instructions (JAR):
1. Download & Install [Java](https://www.oracle.com/java/technologies/downloads/) if not already installed 1. Download & Install [Java](https://www.oracle.com/java/technologies/downloads/) if not already installed
2. Download the [latest release](https://github.com/MistWeatherMedia/WeatherSTAR-3000-Java/releases) .zip file and extract 2. Download the [latest release](https://github.com/MistWeatherMedia/WeatherSTAR-3000-Java/releases) .zip file and extract
3. Run the included .jar file 3. Run the included .jar file
@@ -22,14 +20,6 @@ Either of the following methods can be used:
------------ ------------
## Installation Instructions (EXE): NOT IN USE RIGHT NOW
1. Download and run the [latest release](https://github.com/MistWeatherMedia/WeatherSTAR-3000-Java/releases) .exe installer file
2. Locate the installed program and run it.
3. Locate an api.weather.com API key and configure your settings, then run!
4. OPTIONAL - Drop any mp3 files you want played by the simulator into the "music" folder located in the program's installed directory (usually in C:/Program Files/WeatherSTAR 3000/app)
------------
You're all set. You're all set.
Many thanks for using our simulator! We hope you like it. Many thanks for using our simulator! We hope you like it.
+21 -18
View File
@@ -5,7 +5,7 @@
<groupId>WS3000</groupId> <groupId>WS3000</groupId>
<artifactId>weatherstar3000</artifactId> <artifactId>weatherstar3000</artifactId>
<version>1.2.3</version> <version>1.8.0</version>
<name>weatherstar3000</name> <name>weatherstar3000</name>
<url>https://github.com/MistWeatherMedia/WeatherSTAR-3000-Java</url> <url>https://github.com/MistWeatherMedia/WeatherSTAR-3000-Java</url>
@@ -186,25 +186,15 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>junit-jupiter-api</artifactId>
<version>2.0.13</version> <version>5.10.2</version>
<scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>org.json</groupId>
<artifactId>logback-classic</artifactId> <artifactId>json</artifactId>
<version>1.5.6</version> <version>20231013</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>6.1.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20250517</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javazoom</groupId> <groupId>javazoom</groupId>
@@ -586,6 +576,19 @@
<artifactId>joml</artifactId> <artifactId>joml</artifactId>
<version>${joml.version}</version> <version>${joml.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
<version>1.19.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-jvm</artifactId>
<version>5.5.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

+131 -102
View File
@@ -4,15 +4,17 @@ import org.json.JSONObject;
import util.Utilities; import util.Utilities;
import java.net.URI; import okhttp3.OkHttpClient;
import java.net.http.HttpClient; import okhttp3.Request;
import java.net.http.HttpRequest; import okhttp3.Response;
import java.net.http.HttpResponse;
import java.util.Objects; import java.util.Objects;
public class Almanac extends Thread { public class Almanac extends Thread {
Utilities utl = new Utilities(); Utilities utl = new Utilities();
private final OkHttpClient client = new OkHttpClient();
String today; String today;
String tomorrow; String tomorrow;
String todaySunrise; String todaySunrise;
@@ -24,55 +26,59 @@ public class Almanac extends Thread {
String tomorrowHigh; String tomorrowHigh;
String tomorrowLow; String tomorrowLow;
String normalPrecip; String normalPrecip;
String getDay(String icaoCode, String key, int dayNum) { String getDay(String icaoCode, String key, int dayNum) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) Request request = new Request.Builder()
.GET() .url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try { try (Response response = client.newCall(request).execute()) {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); if (!response.isSuccessful()) {
if (Response.statusCode() != 200) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody); String responseBody = response.body().string();
String day = JSONResponse.getJSONArray("dayOfWeek").getString(dayNum); JSONObject jsonResponse = new JSONObject(responseBody);
String day = jsonResponse.getJSONArray("dayOfWeek").getString(dayNum);
String[] dayNames = {" SUNDAY ", " MONDAY ", " TUESDAY ", "WEDNESDAY", "THURSDAY ", " FRIDAY ", "SATURDAY "}; String[] dayNames = {" SUNDAY ", " MONDAY ", " TUESDAY ", "WEDNESDAY", "THURSDAY ", " FRIDAY ", "SATURDAY "};
return switch (day) { switch (day) {
case "Sunday" -> dayNames[0]; case "Sunday": return dayNames[0];
case "Monday" -> dayNames[1]; case "Monday": return dayNames[1];
case "Tuesday" -> dayNames[2]; case "Tuesday": return dayNames[2];
case "Wednesday" -> dayNames[3]; case "Wednesday": return dayNames[3];
case "Thursday" -> dayNames[4]; case "Thursday": return dayNames[4];
case "Friday" -> dayNames[5]; case "Friday": return dayNames[5];
case "Saturday" -> dayNames[6]; case "Saturday": return dayNames[6];
default -> " "; default: return " ";
}; }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return " "; return " ";
} }
} }
String getSunrise(String icaoCode, String key, int dayNum) { String getSunrise(String icaoCode, String key, int dayNum) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) Request request = new Request.Builder()
.GET() .url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try { try (Response response = client.newCall(request).execute()) {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); if (!response.isSuccessful()) {
if (Response.statusCode() != 200) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody); String responseBody = response.body().string();
String time = JSONResponse.getJSONArray("sunriseTimeLocal").getString(dayNum); JSONObject jsonResponse = new JSONObject(responseBody);
String time = jsonResponse.getJSONArray("sunriseTimeLocal").getString(dayNum);
int hour = Integer.parseInt(time.substring(11, 13)); int hour = Integer.parseInt(time.substring(11, 13));
int dispHour = hour > 12 ? hour - 12 : hour; int dispHour = hour > 12 ? hour - 12 : hour;
@@ -85,22 +91,24 @@ public class Almanac extends Thread {
return " "; return " ";
} }
} }
String getSunset(String icaoCode, String key, int dayNum) { String getSunset(String icaoCode, String key, int dayNum) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) Request request = new Request.Builder()
.GET() .url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try { try (Response response = client.newCall(request).execute()) {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); if (!response.isSuccessful()) {
if (Response.statusCode() != 200) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody); String responseBody = response.body().string();
String time = JSONResponse.getJSONArray("sunsetTimeLocal").getString(dayNum); JSONObject jsonResponse = new JSONObject(responseBody);
String time = jsonResponse.getJSONArray("sunsetTimeLocal").getString(dayNum);
int hour = Integer.parseInt(time.substring(11, 13)); int hour = Integer.parseInt(time.substring(11, 13));
int dispHour = hour > 12 ? hour - 12 : hour; int dispHour = hour > 12 ? hour - 12 : hour;
@@ -113,67 +121,77 @@ public class Almanac extends Thread {
return " "; return " ";
} }
} }
String getMonth(String icaoCode, String key) { String getMonth(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) Request request = new Request.Builder()
.GET() .url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try { try (Response response = client.newCall(request).execute()) {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); if (!response.isSuccessful()) {
if (Response.statusCode() != 200) {
return "error"; return "error";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody); String responseBody = response.body().string();
return JSONResponse.getJSONArray("validTimeLocal").getString(0).substring(5, 7); JSONObject jsonResponse = new JSONObject(responseBody);
return jsonResponse.getJSONArray("validTimeLocal").getString(0).substring(5, 7);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return "error"; return "error";
} }
} }
String getDayDate(String icaoCode, String key) { String getDayDate(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) Request request = new Request.Builder()
.GET() .url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try { try (Response response = client.newCall(request).execute()) {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); if (!response.isSuccessful()) {
if (Response.statusCode() != 200) {
return "error"; return "error";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody); String responseBody = response.body().string();
return JSONResponse.getJSONArray("validTimeLocal").getString(0).substring(8, 10); JSONObject jsonResponse = new JSONObject(responseBody);
return jsonResponse.getJSONArray("validTimeLocal").getString(0).substring(8, 10);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return "error"; return "error";
} }
} }
String getTempMax(String icaoCode, String key, int dayNum, String month, String day) { String getTempMax(String icaoCode, String key, int dayNum, String month, String day) {
if (Objects.equals(month, "error") || Objects.equals(day, "error")) { if (Objects.equals(month, "error") || Objects.equals(day, "error")) {
return " "; return " ";
} }
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder() String url = "https://api.weather.com/v3/wx/almanac/daily/5day?icaoCode=" + icaoCode + "&format=json&units=e&startDay=" + day + "&startMonth=" + month + "&apiKey=" + key;
.uri(URI.create("https://api.weather.com/v3/wx/almanac/daily/5day?icaoCode=" + icaoCode + "&format=json&units=e&startDay=" + day + "&startMonth=" + month + "&apiKey=" + key))
.GET() Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try { try (Response response = client.newCall(request).execute()) {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); if (!response.isSuccessful()) {
if (Response.statusCode() != 200) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody); String responseBody = response.body().string();
int temp = JSONResponse.getJSONArray("temperatureAverageMax").getInt(dayNum); JSONObject jsonResponse = new JSONObject(responseBody);
int temp = jsonResponse.getJSONArray("temperatureAverageMax").getInt(dayNum);
return utl.rjust(temp + " \\F", 6, " "); return utl.rjust(temp + " \\F", 6, " ");
} catch (Exception e) { } catch (Exception e) {
@@ -181,25 +199,29 @@ public class Almanac extends Thread {
return " "; return " ";
} }
} }
String getTempMin(String icaoCode, String key, int dayNum, String month, String day) { String getTempMin(String icaoCode, String key, int dayNum, String month, String day) {
if (Objects.equals(month, "error") || Objects.equals(day, "error")) { if (Objects.equals(month, "error") || Objects.equals(day, "error")) {
return " "; return " ";
} }
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder() String url = "https://api.weather.com/v3/wx/almanac/daily/5day?icaoCode=" + icaoCode + "&format=json&units=e&startDay=" + day + "&startMonth=" + month + "&apiKey=" + key;
.uri(URI.create("https://api.weather.com/v3/wx/almanac/daily/5day?icaoCode=" + icaoCode + "&format=json&units=e&startDay=" + day + "&startMonth=" + month + "&apiKey=" + key))
.GET() Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try { try (Response response = client.newCall(request).execute()) {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); if (!response.isSuccessful()) {
if (Response.statusCode() != 200) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody); String responseBody = response.body().string();
int temp = JSONResponse.getJSONArray("temperatureAverageMin").getInt(dayNum); JSONObject jsonResponse = new JSONObject(responseBody);
int temp = jsonResponse.getJSONArray("temperatureAverageMin").getInt(dayNum);
return utl.rjust(temp + " \\F", 6, " "); return utl.rjust(temp + " \\F", 6, " ");
} catch (Exception e) { } catch (Exception e) {
@@ -207,41 +229,48 @@ public class Almanac extends Thread {
return " "; return " ";
} }
} }
String getPrecip(String icaoCode, String key, String month, String day) { String getPrecip(String icaoCode, String key, String month, String day) {
if (Objects.equals(month, "error") || Objects.equals(day, "error")) { if (Objects.equals(month, "error") || Objects.equals(day, "error")) {
return " "; return utl.ljust("", 32, " ");
} }
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder() String url = "https://api.weather.com/v3/wx/almanac/daily/5day?icaoCode=" + icaoCode + "&format=json&units=e&startDay=" + day + "&startMonth=" + month + "&apiKey=" + key;
.uri(URI.create("https://api.weather.com/v3/wx/almanac/daily/5day?icaoCode=" + icaoCode + "&format=json&units=e&startDay=" + day + "&startMonth=" + month + "&apiKey=" + key))
.GET() Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try { try (Response response = client.newCall(request).execute()) {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); if (!response.isSuccessful()) {
if (Response.statusCode() != 200) { return utl.ljust("", 32, " ");
return " ";
} }
String ResponseBody = Response.body();
String[] monthNames = {"", "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"};
JSONObject JSONResponse = new JSONObject(ResponseBody);
float precip = JSONResponse.getJSONArray("precipitationAverage").getFloat(0);
String precipString = utl.rjust(precip + " IN", 8, " "); String responseBody = response.body().string();
String cmonth = utl.ljust("NORMAL " + monthNames[Integer.parseInt(month)] + " PRECIP", 23, " "); String[] monthNames = {"", "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"};
JSONObject jsonResponse = new JSONObject(responseBody);
String precip = jsonResponse.getJSONArray("precipitationAverage").isNull(0)
? "NO REPORT"
: String.valueOf(jsonResponse.getJSONArray("precipitationAverage").getFloat(0));
String precipString = precip.equals("NO REPORT") ? "NO REPORT" : utl.rjust(precip + " IN", 9, " ");
String cmonth = utl.ljust("NORMAL " + monthNames[Integer.parseInt(month)] + " PRECIP", 22, " ");
return utl.ljust(cmonth + precipString, 31, " ") + " "; return utl.ljust(cmonth + precipString, 31, " ") + " ";
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return " "; return utl.ljust("", 32, " ");
} }
} }
public void run() { public void run() {
String mainIcao = Main.mainIcao; String mainIcao = Main.mainIcao;
String key = Main.key; String key = Main.key;
String todayMonth = Main.todayMonth; String todayMonth = getMonth(mainIcao, key);;
String todayDay = Main.todayDay; String todayDay = getDayDate(mainIcao, key);;
Main.almanac.today = getDay(mainIcao, key, 0); Main.almanac.today = getDay(mainIcao, key, 0);
Main.almanac.tomorrow = getDay(mainIcao, key, 1); Main.almanac.tomorrow = getDay(mainIcao, key, 1);
Main.almanac.todaySunrise = getSunrise(mainIcao, key, 0); Main.almanac.todaySunrise = getSunrise(mainIcao, key, 0);
+105 -107
View File
@@ -1,152 +1,150 @@
package WS3000.weatherstar3000; package WS3000.weatherstar3000;
import java.net.URI; import okhttp3.OkHttpClient;
import java.net.http.HttpClient; import okhttp3.Request;
import java.net.http.HttpRequest; import okhttp3.Response;
import java.net.http.HttpResponse;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import util.Utilities; import util.Utilities;
public class Bulletin extends Thread { public class Bulletin extends Thread {
private final OkHttpClient client = new OkHttpClient();
static Utilities utl = new Utilities(); static Utilities utl = new Utilities();
ArrayList<String> bulletinText = new ArrayList<>(); ArrayList<String> bulletinText = new ArrayList<>();
//String color;
//boolean severe;
//boolean crawl;
public ArrayList<String> getBulletin(String key, String lat, String lon) { public ArrayList<String> getBulletin(String key, String lat, String lon) {
ArrayList<String> words = new ArrayList<>(); ArrayList<String> words = new ArrayList<>();
HttpClient Client = HttpClient.newBuilder().build();
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/alerts/headlines?geocode=" + lat + "," + lon + "&format=json&language=en-US&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
words.clear();
words.add("None");
words.add("NOBULLETINCRAWL");
return words;
}
JSONObject responseObject = new JSONObject(Response.body()); String url = "https://api.weather.com/v3/alerts/headlines?geocode=" + lat + "," + lon + "&format=json&language=en-US&apiKey=" + key;
for (int i = 0; i < responseObject.getJSONArray("alerts").length(); i++) { Request request = new Request.Builder()
String headline = responseObject.getJSONArray("alerts").getJSONObject(i).getString("eventDescription"); .url(url)
.get()
.header("Accept", "application/json")
.build();
String detailKey = responseObject.getJSONArray("alerts").getJSONObject(i).getString("detailKey"); try (Response response = client.newCall(request).execute()) {
if (utl.isScroll(headline)) { if (!response.isSuccessful()) {
return eachAlert(detailKey, key); words.add("None");
} else { words.add("NOBULLETINCRAWL");
continue; return words;
} }
}
words.clear(); JSONObject responseObject = new JSONObject(response.body().string());
words.add("None");
words.add("NOBULLETINCRAWL");
return words; for (int i = 0; i < responseObject.getJSONArray("alerts").length(); i++) {
} catch (Exception e) { JSONObject alertItem = responseObject.getJSONArray("alerts").getJSONObject(i);
e.printStackTrace(); String headline = alertItem.getString("eventDescription");
words.clear(); String detailKey = alertItem.getString("detailKey");
words.add("None");
words.add("NOBULLETINCRAWL"); if (utl.isScroll(headline)) {
return words; return eachAlert(detailKey, key);
} }
} }
words.add("None");
words.add("NOBULLETINCRAWL");
return words;
} catch (Exception e) {
e.printStackTrace();
words.clear();
words.add("None");
words.add("NOBULLETINCRAWL");
return words;
}
}
public ArrayList<String> eachAlert(String detailKey, String key) { public ArrayList<String> eachAlert(String detailKey, String key) {
ArrayList<String> words = new ArrayList<>(); ArrayList<String> words = new ArrayList<>();
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/alerts/detail?alertId=" + detailKey
HttpRequest Request = HttpRequest.newBuilder() + "&format=json&language=en-US&apiKey=" + key;
.uri(URI.create("https://api.weather.com/v3/alerts/detail?alertId=" + detailKey + "&format=json&language=en-US&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
words.clear();
words.add("None");
words.add("NOBULLETINCRAWL");
return words;
}
JSONObject ResponseObj = new JSONObject(Response.body()); Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json")
.build();
String headline = ResponseObj.getJSONObject("alertDetail").getString("eventDescription"); try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
words.add("None");
words.add("NOBULLETINCRAWL");
return words;
}
String alert = ResponseObj.getJSONObject("alertDetail").getJSONArray("texts").getJSONObject(0).getString("description").toUpperCase(); JSONObject responseObj = new JSONObject(response.body().string());
JSONObject alertDetail = responseObj.getJSONObject("alertDetail");
words.clear(); String headline = alertDetail.getString("eventDescription");
String alert = alertDetail.getJSONArray("texts").getJSONObject(0).getString("description").toUpperCase();
words.addAll(Arrays.asList(alert.replace("\n\n", " *newline* ").split("\\s+"))); words.addAll(Arrays.asList(alert.replace("\n\n", " *newline* ").split("\\s+")));
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
ArrayList<String> finalWords = new ArrayList<>(); ArrayList<String> finalWords = new ArrayList<>();
finalWords.add(headline); finalWords.add(headline);
for (int i = 0; i <= words.size()-1; i++) { for (int i = 0; i <= words.size() - 1; i++) {
if (words.get(i).equals("*newline*")) { if (words.get(i).equals("*newline*")) {
if (!sb.isEmpty()) { if (!(sb.length() == 0)) {
finalWords.add(utl.ljust(sb.toString(), 32, " ")); finalWords.add(utl.ljust(sb.toString(), 32, " "));
sb.setLength(0); sb.setLength(0);
} }
finalWords.add(utl.ljust(sb.toString(), 32, " ")); finalWords.add(utl.ljust(sb.toString(), 32, " "));
sb.setLength(0); sb.setLength(0);
continue; continue;
} }
int wordlength = words.get(i).length(); int wordlength = words.get(i).length();
if (wordlength > 32) { if (wordlength > 32) {
finalWords.add(utl.ljust(sb.toString(), 32, " ")); finalWords.add(utl.ljust(sb.toString(), 32, " "));
sb.setLength(0); sb.setLength(0);
if (!sb.isEmpty()) {sb.append(" ");} if (!(sb.length() == 0)) { sb.append(" "); }
sb.append(words.get(i)); sb.append(words.get(i));
finalWords.add(utl.ljust(sb.toString(), 32, " ")); finalWords.add(utl.ljust(sb.toString(), 32, " "));
sb.setLength(0); sb.setLength(0);
} else { } else {
if (wordlength + sb.length() + 1 <= 32) { if (wordlength + sb.length() + 1 <= 32) {
if (!sb.isEmpty()) {sb.append(" ");} if (!(sb.length() == 0)) { sb.append(" "); }
sb.append(words.get(i)); sb.append(words.get(i));
} else { } else {
i--; i--;
finalWords.add(utl.ljust(sb.toString(), 32, " ")); finalWords.add(utl.ljust(sb.toString(), 32, " "));
sb.setLength(0); sb.setLength(0);
} }
} }
} }
finalWords.add(utl.ljust(sb.toString(), 32, " ")); finalWords.add(utl.ljust(sb.toString(), 32, " "));
sb.setLength(0); sb.setLength(0);
return finalWords; return finalWords;
} catch (Exception e) {
words.clear(); } catch (Exception e) {
words.add("None"); e.printStackTrace();
words.add("NOBULLETINCRAWL"); words.clear();
return words; words.add("None");
} words.add("NOBULLETINCRAWL");
return words;
}
} }
public void run() { public void run() {
String key = Main.key; String key = Main.key;
String mainLat = Main.mainLat; String mainLat = Main.mainLat;
String mainLon = Main.mainLon; String mainLon = Main.mainLon;
Main.bulletin.bulletinText.clear();
Main.bulletin.bulletinText = getBulletin(key, mainLat, mainLon); Main.bulletin.bulletinText = getBulletin(key, mainLat, mainLon);
//System.out.println(Main.bulletin.bulletinText);
} }
} }
@@ -4,15 +4,16 @@ import org.json.JSONObject;
import util.Utilities; import util.Utilities;
import java.net.URI; import okhttp3.OkHttpClient;
import java.net.http.HttpClient; import okhttp3.Request;
import java.net.http.HttpRequest; import okhttp3.Response;
import java.net.http.HttpResponse;
//import java.text.DecimalFormat; //import java.text.DecimalFormat;
import java.time.LocalDate; import java.time.ZonedDateTime;
import java.time.Month; import java.time.Month;
public class CurrentConditions extends Thread { public class CurrentConditions extends Thread {
private final OkHttpClient client = new OkHttpClient();
String locName; String locName;
String condition; String condition;
String temperature; String temperature;
@@ -25,46 +26,53 @@ public class CurrentConditions extends Thread {
String visibility; String visibility;
String ceiling; String ceiling;
String precip; String precip;
static Utilities utl = new Utilities();
static String getLocName(String displayName) {return "CONDITIONS AT " + utl.ljust(displayName.toUpperCase(), 14, " ").substring(0, 14);} Utilities utl = new Utilities();
static String getCondition(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String getLocName(String displayName) {return "CONDITIONS AT " + utl.ljust(displayName.toUpperCase(), 14, " ").substring(0, 14);}
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) String getCondition(String icaoCode, String key) {
.GET() String url = "https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return "NO REPORT";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
return JSONResponse.getString("wxPhraseLong").toUpperCase(); try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
return "NO CURRENT REPORT";
}
String responseBody = response.body().string();
JSONObject jsonResponse = new JSONObject(responseBody);
return jsonResponse.getString("wxPhraseLong").toUpperCase();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return "NO REPORT"; return "NO CURRENT REPORT";
} }
} }
static String getTemperature(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String getTemperature(String icaoCode, String key) {
HttpRequest Request = HttpRequest.newBuilder() String url = "https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET() Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); try (Response response = client.newCall(request).execute()) {
if (Response.statusCode() != 200) { if (!response.isSuccessful()) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
String temp = utl.rjust(Integer.toString(JSONResponse.getInt("temperature")), 3, " "); String responseBody = response.body().string();
JSONObject jsonResponse = new JSONObject(responseBody);
String temp = utl.rjust(Integer.toString(jsonResponse.getInt("temperature")), 3, " ");
return "TEMP: " + temp + "\\F"; return "TEMP: " + temp + "\\F";
} catch (Exception e) { } catch (Exception e) {
@@ -72,23 +80,27 @@ public class CurrentConditions extends Thread {
return " "; return " ";
} }
} }
static String getFeelsLike(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String getFeelsLike(String icaoCode, String key) {
HttpRequest Request = HttpRequest.newBuilder() String url = "https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET() Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); try (Response response = client.newCall(request).execute()) {
if (Response.statusCode() != 200) { if (!response.isSuccessful()) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
int feelTemp = JSONResponse.getInt("temperatureFeelsLike"); String responseBody = response.body().string();
int temp = JSONResponse.getInt("temperature"); JSONObject jsonResponse = new JSONObject(responseBody);
int feelTemp = jsonResponse.getInt("temperatureFeelsLike");
int temp = jsonResponse.getInt("temperature");
if (temp == feelTemp) { if (temp == feelTemp) {
return " "; return " ";
} else { } else {
@@ -98,28 +110,31 @@ public class CurrentConditions extends Thread {
return "WIND CHILL:" + utl.rjust(Integer.toString(feelTemp), 3, " ") + "\\F"; return "WIND CHILL:" + utl.rjust(Integer.toString(feelTemp), 3, " ") + "\\F";
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return " "; return " ";
} }
} }
static String getHumidity(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String getHumidity(String icaoCode, String key) {
HttpRequest Request = HttpRequest.newBuilder() String url = "https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) + "&units=e&language=en-US&format=json&apiKey=" + key;
.GET()
Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); try (Response response = client.newCall(request).execute()) {
if (Response.statusCode() != 200) { if (!response.isSuccessful()) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
String humid = utl.rjust(Integer.toString(JSONResponse.getInt("relativeHumidity")), 3, " "); String responseBody = response.body().string();
JSONObject jsonResponse = new JSONObject(responseBody);
String humid = utl.rjust(Integer.toString(jsonResponse.getInt("relativeHumidity")), 3, " ");
return "HUMIDITY: " + humid + "%"; return "HUMIDITY: " + humid + "%";
} catch (Exception e) { } catch (Exception e) {
@@ -127,22 +142,26 @@ public class CurrentConditions extends Thread {
return " "; return " ";
} }
} }
static String getDewPoint(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String getDewPoint(String icaoCode, String key) {
HttpRequest Request = HttpRequest.newBuilder() String url = "https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) + "&units=e&language=en-US&format=json&apiKey=" + key;
.GET()
Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); try (Response response = client.newCall(request).execute()) {
if (Response.statusCode() != 200) { if (!response.isSuccessful()) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
String dewpt = utl.rjust(Integer.toString(JSONResponse.getInt("temperatureDewPoint")), 3, " "); String responseBody = response.body().string();
JSONObject jsonResponse = new JSONObject(responseBody);
String dewpt = utl.rjust(Integer.toString(jsonResponse.getInt("temperatureDewPoint")), 3, " ");
return "DEWPOINT:" + dewpt + "\\F"; return "DEWPOINT:" + dewpt + "\\F";
} catch (Exception e) { } catch (Exception e) {
@@ -150,26 +169,29 @@ public class CurrentConditions extends Thread {
return " "; return " ";
} }
} }
static String getPressure(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String getPressure(String icaoCode, String key) {
HttpRequest Request = HttpRequest.newBuilder() String url = "https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) + "&units=e&language=en-US&format=json&apiKey=" + key;
.GET()
Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); try (Response response = client.newCall(request).execute()) {
if (Response.statusCode() != 200) { if (!response.isSuccessful()) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
//DecimalFormat df = new DecimalFormat("#.##"); String responseBody = response.body().string();
float pres = JSONResponse.getFloat("pressureAltimeter"); JSONObject jsonResponse = new JSONObject(responseBody);
float pres = jsonResponse.getFloat("pressureAltimeter");
String fpres = String.format("%.2f", pres); String fpres = String.format("%.2f", pres);
int presCode = JSONResponse.getInt("pressureTendencyCode"); int presCode = jsonResponse.getInt("pressureTendencyCode");
String fpresCode = ""; String fpresCode = "";
if (presCode == 0) { if (presCode == 0) {
fpresCode = "IN."; fpresCode = "IN.";
@@ -185,51 +207,60 @@ public class CurrentConditions extends Thread {
return " "; return " ";
} }
} }
static String getWind(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String getWind(String icaoCode, String key) {
HttpRequest Request = HttpRequest.newBuilder() String url = "https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) + "&units=e&language=en-US&format=json&apiKey=" + key;
.GET()
Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); try (Response response = client.newCall(request).execute()) {
if (Response.statusCode() != 200) { if (!response.isSuccessful()) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
int windDir = JSONResponse.getInt("windDirection"); String responseBody = response.body().string();
int windSpeed = JSONResponse.getInt("windSpeed"); JSONObject jsonResponse = new JSONObject(responseBody);
int windDir = jsonResponse.getInt("windDirection");
int windSpeed = jsonResponse.getInt("windSpeed");
if (windSpeed == 0) { if (windSpeed == 0) {
return "WIND: CALM "; return "WIND: CALM ";
} else { } else {
return "WIND: " + utl.degToThreeLetter(windDir) + utl.rjust(Integer.toString(windSpeed), 3, " ") + " MPH"; return "WIND: " + utl.degToThreeLetter(windDir) + utl.rjust(Integer.toString(windSpeed), 3, " ") + " MPH";
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return " "; return " ";
} }
} }
static String getGusts(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String getGusts(String icaoCode, String key) {
HttpRequest Request = HttpRequest.newBuilder() String url = "https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) + "&units=e&language=en-US&format=json&apiKey=" + key;
.GET()
Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); try (Response response = client.newCall(request).execute()) {
if (Response.statusCode() != 200) { if (!response.isSuccessful()) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
String gus; String responseBody = response.body().string();
gus = JSONResponse.isNull("windGust") ? " " : "GUSTS TO " + utl.rjust(Integer.toString(JSONResponse.getInt("windGust")), 3, " "); JSONObject jsonResponse = new JSONObject(responseBody);
String gus = jsonResponse.isNull("windGust")
? " "
: "GUSTS TO " + utl.rjust(Integer.toString(jsonResponse.getInt("windGust")), 3, " ");
return gus; return gus;
} catch (Exception e) { } catch (Exception e) {
@@ -237,22 +268,26 @@ public class CurrentConditions extends Thread {
return " "; return " ";
} }
} }
static String getVisiblity(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String getVisiblity(String icaoCode, String key) {
HttpRequest Request = HttpRequest.newBuilder() String url = "https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) + "&units=e&language=en-US&format=json&apiKey=" + key;
.GET()
Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); try (Response response = client.newCall(request).execute()) {
if (Response.statusCode() != 200) { if (!response.isSuccessful()) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
String visib = utl.rjust(Integer.toString(JSONResponse.getInt("visibility")) + " MI.", 7, " "); String responseBody = response.body().string();
JSONObject jsonResponse = new JSONObject(responseBody);
String visib = utl.rjust(Integer.toString(jsonResponse.getInt("visibility")) + " MI.", 7, " ");
return "VISIB: " + visib; return "VISIB: " + visib;
} catch (Exception e) { } catch (Exception e) {
@@ -260,49 +295,58 @@ public class CurrentConditions extends Thread {
return " "; return " ";
} }
} }
String getCeiling(String icaoCode, String key) { String getCeiling(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode
HttpRequest Request = HttpRequest.newBuilder() + "&units=e&language=en-US&format=json&apiKey=" + key;
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET() Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); try (Response response = client.newCall(request).execute()) {
if (Response.statusCode() != 200) { if (!response.isSuccessful()) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
String ceil = JSONResponse.isNull("cloudCeiling") ? "UNLIMITED" : utl.rjust(JSONResponse.getInt("cloudCeiling") + " FT.", 9, " "); String responseBody = response.body().string();
JSONObject jsonResponse = new JSONObject(responseBody);
return "CEILING:" + ceil;//three length String ceil = jsonResponse.isNull("cloudCeiling")
? "UNLIMITED"
: utl.rjust(jsonResponse.getInt("cloudCeiling") + " FT.", 9, " ");
return "CEILING:" + ceil;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return " "; return " ";
} }
} }
String getPrecip(String key, String lat, String lon) { String getPrecip(String key, String lat, String lon) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v1/geocode/" + lat + "/" + lon + "/observations/current.json?language=en-US&units=e&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v1/geocode/" + lat + "/" + lon + "/observations/current.json?language=en-US&units=e&apiKey=" + key)) Request request = new Request.Builder()
.GET() .url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); try (Response response = client.newCall(request).execute()) {
if (Response.statusCode() != 200) { if (!response.isSuccessful()) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
LocalDate cdate = LocalDate.now(); String responseBody = response.body().string();
JSONObject jsonResponse = new JSONObject(responseBody);
ZonedDateTime cdate = ZonedDateTime.now(Main.timeZone);
Month cmonth = cdate.getMonth(); Month cmonth = cdate.getMonth();
try { try {
JSONObject obsObject = JSONResponse.getJSONObject("observation"); JSONObject obsObject = jsonResponse.getJSONObject("observation");
JSONObject impObj = obsObject.getJSONObject("imperial"); JSONObject impObj = obsObject.getJSONObject("imperial");
String fprecip = String.format("%.2f", impObj.getFloat("precip_mtd")); String fprecip = String.format("%.2f", impObj.getFloat("precip_mtd"));
String prec = utl.rjust(fprecip + " IN", 8, " "); String prec = utl.rjust(fprecip + " IN", 8, " ");
@@ -316,6 +360,7 @@ public class CurrentConditions extends Thread {
return " "; return " ";
} }
} }
public void run() { public void run() {
String mainLocName = Main.mainLocName.getText(); String mainLocName = Main.mainLocName.getText();
String key = Main.key; String key = Main.key;
@@ -2,40 +2,64 @@ package WS3000.weatherstar3000;
public class DataRunner extends Thread { public class DataRunner extends Thread {
public void run() { public void run() {
if (Main.ztOption.equals("Location Time")) {
Main.timeZone = Main.getTimeZone(Main.mainIcao);
}
//System.out.println("Data collection"); //System.out.println("Data collection");
Main.currentConditions = new CurrentConditions(); Main.currentConditions = new CurrentConditions();
Main.hourlyObservations = new HourlyObservations(); Main.hourlyObservations = new HourlyObservations();
Main.regionalConditions = new RegionalConditions(); Main.regionalConditions = new RegionalConditions();
Main.localForecast = new LocalForecast(); Main.localForecast = new LocalForecast();
Main.almanac = new Almanac();
if (Main.tidesEnabled) {
Main.tides = new Tides();
} else {
Main.almanac = new Almanac();
}
Main.regionalForecast = new RegionalForecast(); Main.regionalForecast = new RegionalForecast();
Main.extendedForecast = new ExtendedForecast(); Main.extendedForecast = new ExtendedForecast();
Main.outlook = new Outlook(); Main.outlook = new Outlook();
Main.travelForecast = new TravelForecast(); Main.travelForecast = new TravelForecast();
Main.bulletin = new Bulletin(); Main.bulletin = new Bulletin();
Main.currentConditions.start(); Main.currentConditions.start();
Main.hourlyObservations.start(); Main.hourlyObservations.start();
Main.regionalConditions.start(); Main.regionalConditions.start();
Main.localForecast.start(); Main.localForecast.start();
Main.almanac.start();
if (Main.tidesEnabled) {
Main.tides.start();
} else {
Main.almanac.start();
}
Main.regionalForecast.start(); Main.regionalForecast.start();
Main.extendedForecast.start(); Main.extendedForecast.start();
Main.outlook.start(); Main.outlook.start();
Main.travelForecast.start(); Main.travelForecast.start();
Main.bulletin.start(); Main.bulletin.start();
try { try {
Main.currentConditions.join(); Main.currentConditions.join();
Main.hourlyObservations.join(); Main.hourlyObservations.join();
Main.regionalConditions.join(); Main.regionalConditions.join();
Main.localForecast.join(); Main.localForecast.join();
Main.almanac.join();
if (Main.tidesEnabled) {
Main.tides.join();
} else {
Main.almanac.join();
}
Main.regionalForecast.join(); Main.regionalForecast.join();
Main.extendedForecast.join(); Main.extendedForecast.join();
Main.outlook.join(); Main.outlook.join();
Main.travelForecast.join(); Main.travelForecast.join();
Main.bulletin.join(); Main.bulletin.join();
LoadingScreen.dataFinish = true; LoadingScreen.dataFinish = true;
SlidesRunner.collectingData = false; SlidesRunner.collectingData = false;
//ystem.out.println("data finished, destroying thread"); //ystem.out.println("data finished, destroying thread");
@@ -1,9 +1,9 @@
package WS3000.weatherstar3000; package WS3000.weatherstar3000;
import java.net.URI; import okhttp3.OkHttpClient;
import java.net.http.HttpClient; import okhttp3.Request;
import java.net.http.HttpRequest; import okhttp3.Response;
import java.net.http.HttpResponse;
import java.util.ArrayList; import java.util.ArrayList;
import org.json.JSONObject; import org.json.JSONObject;
@@ -11,6 +11,8 @@ import org.json.JSONObject;
import util.Utilities; import util.Utilities;
public class ExtendedForecast extends Thread { public class ExtendedForecast extends Thread {
private final OkHttpClient client = new OkHttpClient();
String dayOne; String dayOne;
String dayTwo; String dayTwo;
String dayThree; String dayThree;
@@ -24,109 +26,122 @@ public class ExtendedForecast extends Thread {
String highTwo; String highTwo;
String highThree; String highThree;
Utilities utl = new Utilities(); Utilities utl = new Utilities();
String getDayName(String icaoCode, String key, int day) { String getDayName(String icaoCode, String key, int day) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
//JSONObject JSONResponse = new JSONObject(ResponseBody);
//JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
//int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 1 : 0;
return utl.ljust(new JSONObject(ResponseBody).getJSONArray("dayOfWeek").getString(day + 2).toUpperCase(), 10, " "); Request request = new Request.Builder()
} catch (Exception e) { .url(url)
e.printStackTrace(); .get()
return " "; .header("Accept", "application/json")
} .build();
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
return " ";
}
String responseBody = response.body().string();
return utl.ljust(new JSONObject(responseBody).getJSONArray("dayOfWeek").getString(day + 2).toUpperCase(), 10, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} }
ArrayList<String> getCondition(String icaoCode, String key, int day) { ArrayList<String> getCondition(String icaoCode, String key, int day) {
ArrayList<String> values = new ArrayList<>(); ArrayList<String> values = new ArrayList<>();
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
values.add(" ");
values.add(" ");
return values;
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 5 : 4;
int ex = day*2;
values.add(utl.getForecastEx(dpData.getJSONArray("iconCodeExtend").getInt(ex + bump), 0)); Request request = new Request.Builder()
values.add(utl.getForecastEx(dpData.getJSONArray("iconCodeExtend").getInt(ex + bump), 1)); .url(url)
.get()
.header("Accept", "application/json")
.build();
return values; try (Response response = client.newCall(request).execute()) {
} catch (Exception e) { if (!response.isSuccessful()) {
e.printStackTrace(); values.add(" ");
values.add(" "); values.add(" ");
values.add(" "); return values;
return values; }
}
String responseBody = response.body().string();
JSONObject jsonResponse = new JSONObject(responseBody);
JSONObject dpData = jsonResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 6 : dpData.getJSONArray("dayOrNight").getString(0).equals("N") ? 6 : 4;
int ex = day * 2;
values.add(utl.getForecastEx(dpData.getJSONArray("iconCodeExtend").getInt(ex + bump), 0));
values.add(utl.getForecastEx(dpData.getJSONArray("iconCodeExtend").getInt(ex + bump), 1));
return values;
} catch (Exception e) {
e.printStackTrace();
values.clear();
values.add(" ");
values.add(" ");
return values;
}
} }
String getLow(String icaoCode, String key, int day) { String getLow(String icaoCode, String key, int day) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode
HttpRequest Request = HttpRequest.newBuilder() + "&units=e&language=en-US&format=json&apiKey=" + key;
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 5 : 4;
int ex = day*2;
return "LO:" + utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(ex + bump + 1)), 4, " ") + " "; Request request = new Request.Builder()
} catch (Exception e) { .url(url)
e.printStackTrace(); .get()
return " "; .header("Accept", "application/json")
} .build();
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
return " ";
}
String responseBody = response.body().string();
JSONObject jsonResponse = new JSONObject(responseBody);
JSONObject dpData = jsonResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 5 : 4;
int ex = day * 2;
return "LO:" + utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(ex + bump + 1)), 4, " ") + " ";
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} }
String getHigh(String icaoCode, String key, int day) { String getHigh(String icaoCode, String key, int day) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode
HttpRequest Request = HttpRequest.newBuilder() + "&units=e&language=en-US&format=json&apiKey=" + key;
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET()
.header("Accept", "application/json")
.build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) {
return " ";
}
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 5 : 4;
int ex = day*2;
return "HI:" + utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(ex + bump)), 4, " ") + " "; Request request = new Request.Builder()
} catch (Exception e) { .url(url)
e.printStackTrace(); .get()
return " "; .header("Accept", "application/json")
} .build();
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
return " ";
}
String responseBody = response.body().string();
JSONObject jsonResponse = new JSONObject(responseBody);
JSONObject dpData = jsonResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 5 : 4;
int ex = day * 2;
return "HI:" + utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(ex + bump)), 4, " ") + " ";
} catch (Exception e) {
e.printStackTrace();
return " ";
}
} }
public void run() { public void run() {
String key = Main.key; String key = Main.key;
String mainIcao = Main.mainIcao; String mainIcao = Main.mainIcao;
@@ -4,13 +4,15 @@ import org.json.JSONObject;
import util.Utilities; import util.Utilities;
import java.net.URI; import okhttp3.OkHttpClient;
import java.net.http.HttpClient; import okhttp3.Request;
import java.net.http.HttpRequest; import okhttp3.Response;
import java.net.http.HttpResponse;
import java.util.ArrayList; import java.util.ArrayList;
public class HourlyObservations extends Thread { public class HourlyObservations extends Thread {
private final OkHttpClient client = new OkHttpClient();
ArrayList<String> locName = new ArrayList<>(); ArrayList<String> locName = new ArrayList<>();
ArrayList<String> temperature = new ArrayList<>(); ArrayList<String> temperature = new ArrayList<>();
ArrayList<String> condition = new ArrayList<>(); ArrayList<String> condition = new ArrayList<>();
@@ -18,67 +20,76 @@ public class HourlyObservations extends Thread {
Utilities utl = new Utilities(); Utilities utl = new Utilities();
String getLocName(String displayName) { String getLocName(String displayName) {
return utl.ljust(displayName, 14, " ").substring(0, 14); return utl.ljust(displayName, 14, " ").toUpperCase().substring(0, 14);
} }
String getTemperature(String icaoCode, String key) { String getTemperature(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) Request request = new Request.Builder()
.GET() .url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); try (Response response = client.newCall(request).execute()) {
if (Response.statusCode() != 200) { if (!response.isSuccessful()) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
return utl.rjust(Integer.toString(JSONResponse.getInt("temperature")), 3, " "); String responseBody = response.body().string();
JSONObject jsonResponse = new JSONObject(responseBody);
return utl.rjust(Integer.toString(jsonResponse.getInt("temperature")), 3, " ");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return " "; return " ";
} }
} }
String getCondition(String icaoCode, String key) { String getCondition(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) Request request = new Request.Builder()
.GET() .url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); try (Response response = client.newCall(request).execute()) {
if (Response.statusCode() != 200) { if (!response.isSuccessful()) {
return "NO REPORT"; return "NO REPORT";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
return utl.getCondition(JSONResponse.getInt("iconCodeExtend")); String responseBody = response.body().string();
JSONObject jsonResponse = new JSONObject(responseBody);
return utl.getCondition(jsonResponse.getInt("iconCodeExtend"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return "NO REPORT"; return "NO REPORT";
} }
} }
String getWind(String icaoCode, String key) { String getWind(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) Request request = new Request.Builder()
.GET() .url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); try (Response response = client.newCall(request).execute()) {
if (Response.statusCode() != 200) { if (!response.isSuccessful()) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
int windDir = JSONResponse.getInt("windDirection"); String responseBody = response.body().string();
int windSpeed = JSONResponse.getInt("windSpeed"); JSONObject jsonResponse = new JSONObject(responseBody);
int windDir = jsonResponse.getInt("windDirection");
int windSpeed = jsonResponse.getInt("windSpeed");
return utl.formatWind(windSpeed, windDir, false); return utl.formatWind(windSpeed, windDir, false);
} catch (Exception e) { } catch (Exception e) {
@@ -86,12 +97,17 @@ public class HourlyObservations extends Thread {
return " "; return " ";
} }
} }
public void run() { public void run() {
ArrayList<String> nearNames = new ArrayList<>(); ArrayList<String> nearNames = new ArrayList<>();
nearNames.addAll(Main.nearNames); nearNames.addAll(Main.nearNames);
ArrayList<String> nearIcaos = new ArrayList<>();; ArrayList<String> nearIcaos = new ArrayList<>();;
nearIcaos.addAll(Main.nearIcaos); nearIcaos.addAll(Main.nearIcaos);
String key = Main.key; String key = Main.key;
Main.hourlyObservations.locName.clear();
Main.hourlyObservations.temperature.clear();
Main.hourlyObservations.condition.clear();
Main.hourlyObservations.wind.clear();
for (int i = 0; i < nearIcaos.size(); i++) { for (int i = 0; i < nearIcaos.size(); i++) {
Main.hourlyObservations.locName.add(getLocName(nearNames.get(i))); Main.hourlyObservations.locName.add(getLocName(nearNames.get(i)));
Main.hourlyObservations.temperature.add(getTemperature(nearIcaos.get(i), key)); Main.hourlyObservations.temperature.add(getTemperature(nearIcaos.get(i), key));
@@ -5,14 +5,16 @@ import org.json.JSONObject;
import util.Utilities; import util.Utilities;
import java.net.URI; import okhttp3.OkHttpClient;
import java.net.http.HttpClient; import okhttp3.Request;
import java.net.http.HttpRequest; import okhttp3.Response;
import java.net.http.HttpResponse;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
public class LocalForecast extends Thread { public class LocalForecast extends Thread {
private final OkHttpClient client = new OkHttpClient();
ArrayList<String> bulletin = new ArrayList<>(); ArrayList<String> bulletin = new ArrayList<>();
ArrayList<String> forecastOne = new ArrayList<>(); ArrayList<String> forecastOne = new ArrayList<>();
ArrayList<String> forecastTwo = new ArrayList<>(); ArrayList<String> forecastTwo = new ArrayList<>();
@@ -21,23 +23,28 @@ public class LocalForecast extends Thread {
ArrayList<String> getForecast(String icaoCode, String key, int forecastId) { ArrayList<String> getForecast(String icaoCode, String key, int forecastId) {
ArrayList<String> words = new ArrayList<>(); ArrayList<String> words = new ArrayList<>();
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode
HttpRequest Request = HttpRequest.newBuilder() + "&units=e&language=en-US&format=json&apiKey=" + key;
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
.GET() Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); try (Response response = client.newCall(request).execute()) {
if (Response.statusCode() != 200) { if (!response.isSuccessful()) {
words.add("NO REPORT"); words.add("NO");
words.add("REPORT");
return words; return words;
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody); String responseBody = response.body().string();
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0); JSONObject jsonResponse = new JSONObject(responseBody);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 1 : 0; JSONObject dpData = jsonResponse.getJSONArray("daypart").getJSONObject(0);
String fullText = dpData.getJSONArray("daypartName").getString(forecastId + bump).replaceAll("Tomorrow", JSONResponse.getJSONArray("dayOfWeek").getString(bump)).toUpperCase() + int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 1 : dpData.getJSONArray("dayOrNight").getString(0).equals("N") ? 1 : 0;
String fullText = dpData.getJSONArray("daypartName").getString(forecastId + bump).replaceAll("Tomorrow", jsonResponse.getJSONArray("dayOfWeek").getString(1)).toUpperCase() +
"..." + "..." +
dpData.getJSONArray("narrative").getString(forecastId + bump).toUpperCase(); dpData.getJSONArray("narrative").getString(forecastId + bump).toUpperCase();
String[] splitwords = fullText.split("\\s+"); String[] splitwords = fullText.split("\\s+");
@@ -48,48 +55,50 @@ public class LocalForecast extends Thread {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
words.clear(); words.clear();
words.add("NO REPORT"); words.add("NO");
words.add("REPORT");
return words; return words;
} }
} }
ArrayList<String> getBulletin(String key, String lat, String lon) { ArrayList<String> getBulletin(String key, String lat, String lon) {
ArrayList<String> words = new ArrayList<>(); ArrayList<String> words = new ArrayList<>();
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/alerts/headlines?geocode=" + lat + "," + lon
HttpRequest Request = HttpRequest.newBuilder() + "&format=json&language=en-US&apiKey=" + key;
.uri(URI.create("https://api.weather.com/v3/alerts/headlines?geocode=" + lat + "," + lon + "&format=json&language=en-US&apiKey=" + key))
.GET() Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); try (Response response = client.newCall(request).execute()) {
if (Response.statusCode() != 200) { if (!response.isSuccessful()) {
words.add("NOBULLETIN"); words.add("NOBULLETIN");
return words; return words;
} }
String ResponseBody = Response.body(); String responseBody = response.body().string();
JSONObject JSONResponse = new JSONObject(ResponseBody); JSONObject jsonResponse = new JSONObject(responseBody);
JSONArray alertData = JSONResponse.getJSONArray("alerts"); JSONArray alertData = jsonResponse.getJSONArray("alerts");
StringBuilder fullText = new StringBuilder(); StringBuilder fullText = new StringBuilder();
fullText.setLength(0);
for (int i = 0; i < alertData.length(); i++) { for (int i = 0; i < alertData.length(); i++) {
if (utl.isHeadline(alertData.getJSONObject(i).getString("eventDescription"))) { if (utl.isHeadline(alertData.getJSONObject(i).getString("eventDescription"))) {
if (!fullText.isEmpty()) {fullText.append(" *NEWLINE* ");} if (!(fullText.length() == 0)) {
fullText.append(alertData.getJSONObject(i).getString("headlineText").toUpperCase()); fullText.append(" *NEWLINE* ");
} }
fullText.append(alertData.getJSONObject(i).getString("headlineText").toUpperCase());
}
} }
words.clear(); words.clear();
if (!fullText.isEmpty()) { if (!(fullText.length() == 0)) {
String[] splitwords = fullText.toString().split("\\s+"); String[] splitwords = fullText.toString().split("\\s+");
words.addAll(Arrays.asList(splitwords));
words.addAll(Arrays.asList(splitwords));
} else { } else {
words.add("NOBULLETIN"); words.add("NOBULLETIN");
} }
return words; return words;
@@ -100,6 +109,7 @@ public class LocalForecast extends Thread {
return words; return words;
} }
} }
public void run() { public void run() {
String mainIcao = Main.mainIcao; String mainIcao = Main.mainIcao;
String key = Main.key; String key = Main.key;
File diff suppressed because it is too large. Load diff
+226 -22
View File
@@ -1,35 +1,239 @@
package WS3000.weatherstar3000; package WS3000.weatherstar3000;
//import java.net.URI; import org.locationtech.jts.geom.Coordinate;
//import java.net.http.HttpClient; import org.locationtech.jts.geom.GeometryFactory;
//import java.net.http.HttpRequest; import org.locationtech.jts.geom.Point;
//import java.net.http.HttpResponse; import org.locationtech.jts.geom.Polygon;
import java.time.LocalDate; import org.w3c.dom.Document;
import java.time.Month; import org.w3c.dom.Element;
import java.util.ArrayList; import org.w3c.dom.NodeList;
import java.net.URI;
import java.net.URL;
import java.time.DayOfWeek;
import java.time.ZonedDateTime;
import java.time.temporal.TemporalAdjusters;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.InputStream;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import util.Utilities; import util.Utilities;
//import org.json.JSONObject;
public class Outlook extends Thread { public class Outlook extends Thread {
static Utilities utl = new Utilities(); static Utilities utl = new Utilities();
String month; String month;
ArrayList<String> outlook = new ArrayList<>(); String precipitation;
String getMonth() { String temperature;
LocalDate cdate = LocalDate.now();
Month cmonth = cdate.getMonth();
return cmonth.name().toUpperCase(); private static final GeometryFactory geometryFactory = new GeometryFactory();
}
ArrayList<String> getOutlook() { String getOutlook(String type, String lat, String lon) {//type prcp or temp
ArrayList<String> outlook = new ArrayList<>(); try {
outlook.add("NO"); String zipFile = "https://ftp.cpc.ncep.noaa.gov/GIS/us_tempprcpfcst/monthlyupdate/monthupd_" + type + "_latest.zip";
outlook.add("REPORT");
return outlook; try {
InputStream kmlStream = getKmlStreamFromUrl(zipFile);
if (kmlStream == null) {
System.err.println("No .kml file found inside the ZIP archive.");
return utl.ljust("NO REPORT", 17, " ");
}
List<NamedPolygon> polygons = parseKmlPolygons(kmlStream);
Point userPoint = geometryFactory.createPoint(new Coordinate(Double.parseDouble(lon), Double.parseDouble(lat)));
String matchedPolygonName = findContainingPolygon(polygons, userPoint);
if (matchedPolygonName != null) {
if (matchedPolygonName.contains("Above")) {
return utl.ljust("ABOVE NORMAL", 17, " ");
} else if (matchedPolygonName.contains("Below")) {
return utl.ljust("BELOW NORMAL", 17, " ");
} else {
return utl.ljust("NORMAL", 17, " ");
}
} else {
return utl.ljust("NO REPORT", 17, " ");
}
} catch (Exception e) {
e.printStackTrace();
return utl.ljust("NO REPORT", 17, " ");
}
} catch (Exception e) {
e.printStackTrace();
return utl.ljust("NO REPORT", 17, " ");
}
} }
private InputStream getKmlStreamFromUrl(String zipUrl) {
try {
URL url = URI.create(zipUrl).toURL();
ZipInputStream zis = new ZipInputStream(url.openStream());
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (!entry.isDirectory() && entry.getName().toLowerCase().endsWith(".kml")) {
return zis;
}
}
return null;
} catch (Exception e) {
return null;
}
}
private List<NamedPolygon> parseKmlPolygons(InputStream kmlStream) throws Exception {
List<NamedPolygon> result = new ArrayList<>();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(kmlStream);
NodeList placemarks = doc.getElementsByTagName("Placemark");
for (int i = 0; i < placemarks.getLength(); i++) {
Element placemark = (Element) placemarks.item(i);
NodeList nameNodes = placemark.getElementsByTagName("name");
String name = nameNodes.getLength() > 0 ? nameNodes.item(0).getTextContent().trim() : "Unnamed";
NodeList polygonNodes = placemark.getElementsByTagName("Polygon");
for (int j = 0; j < polygonNodes.getLength(); j++) {
Element polygonEl = (Element) polygonNodes.item(j);
NodeList coordsNodes = polygonEl.getElementsByTagName("coordinates");
if (coordsNodes.getLength() > 0) {
String rawCoords = coordsNodes.item(0).getTextContent();
Polygon polygon = buildJtsPolygon(rawCoords);
if (polygon != null) {
result.add(new NamedPolygon(name, polygon));
}
}
}
}
return result;
}
private static Polygon buildJtsPolygon(String rawCoords) {
String[] pointsStr = rawCoords.trim().split("\\s+");
List<Coordinate> coordsList = new ArrayList<>();
for (String p : pointsStr) {
p = p.trim();
if (p.isEmpty()) continue;
String[] parts = p.split(",");
if (parts.length >= 2) {
try {
double lon = Double.parseDouble(parts[0]);
double lat = Double.parseDouble(parts[1]);
coordsList.add(new Coordinate(lon, lat));
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}
if (coordsList.size() < 3) return null;
if (!coordsList.get(0).equals2D(coordsList.get(coordsList.size() - 1))) {
coordsList.add(coordsList.get(0));
}
Coordinate[] coordsArray = coordsList.toArray(new Coordinate[0]);
return geometryFactory.createPolygon(coordsArray);
}
private String findContainingPolygon(List<NamedPolygon> polygons, Point point) {
for (NamedPolygon np : polygons) {
if (np.polygon.covers(point)) {
return np.name;
}
}
return null;
}
private String getOutlookTitle() {
try {
ZonedDateTime today = ZonedDateTime.now(Main.timeZone);
String[] monthsShorter = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC", "JAN"};
String[] monthsShort = {"JAN", "FEB", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUG", "SEPT", "OCT", "NOV", "DEC", "JAN"};
String[] monthsLong = {"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER", "JANUARY"};
String zipFile = "https://ftp.cpc.ncep.noaa.gov/GIS/us_tempprcpfcst/monthlyupdate/monthupd_temp_latest.zip";
int cMonthVal = ZonedDateTime.now(Main.timeZone).getMonthValue()-1;
String currentMonth = monthsShorter[cMonthVal];
String dataMonth = "";
InputStream kmlStream = getKmlStreamFromUrl(zipFile);
if (kmlStream == null) {
System.err.println("No .kml file found inside the ZIP archive.");
return utl.ljust("", 32, " ");
}
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(kmlStream);
Element root = doc.getDocumentElement();
if (root.hasAttribute("id")) {
dataMonth = parseMonth(root.getAttribute("id").toUpperCase());
}
if (today.isAfter(today.withDayOfMonth(1).with(TemporalAdjusters.dayOfWeekInMonth(3, DayOfWeek.THURSDAY)))) {
if (currentMonth.equals(dataMonth)) {
return utl.cjust("MID " + monthsShort[cMonthVal] + " - MID " + monthsShort[cMonthVal+1], 32, " ");
} else {
return utl.cjust(monthsLong[cMonthVal+1], 32, " ");
}
} else {
return utl.cjust(monthsLong[cMonthVal], 32, " ");
}
} catch (Exception e) {
return utl.ljust("", 32, " ");
}
}
private String parseMonth(String text) {
if (text == null) {
return "";
}
Pattern pattern = Pattern.compile("Valid\\s+([A-Za-z]{3})", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(text);
if (matcher.find()) {
return matcher.group(1).toUpperCase();
}
return "";
}
public void run() { public void run() {
Main.outlook.month = getMonth(); String mainLat = Main.mainLat;
Main.outlook.outlook = getOutlook(); String mainLon = Main.mainLon;
Main.outlook.month = getOutlookTitle();
Main.outlook.temperature = getOutlook("temp", mainLat, mainLon);
Main.outlook.precipitation = getOutlook("prcp", mainLat, mainLon);
} }
} }
class NamedPolygon {
String name;
Polygon polygon;
NamedPolygon(String name, Polygon polygon) {
this.name = name;
this.polygon = polygon;
}
}
@@ -4,69 +4,81 @@ import org.json.JSONObject;
import util.Utilities; import util.Utilities;
import java.net.URI; import okhttp3.OkHttpClient;
import java.net.http.HttpClient; import okhttp3.Request;
import java.net.http.HttpRequest; import okhttp3.Response;
import java.net.http.HttpResponse;
import java.util.ArrayList; import java.util.ArrayList;
public class RegionalConditions extends Thread { public class RegionalConditions extends Thread {
private final OkHttpClient client = new OkHttpClient();
ArrayList<String> locName = new ArrayList<>(); ArrayList<String> locName = new ArrayList<>();
ArrayList<String> temperature = new ArrayList<>(); ArrayList<String> temperature = new ArrayList<>();
ArrayList<String> condition = new ArrayList<>(); ArrayList<String> condition = new ArrayList<>();
Utilities utl = new Utilities(); Utilities utl = new Utilities();
String getLocName(String displayName){ String getLocName(String displayName){
return utl.ljust(displayName, 19, " ").substring(0, 19); return utl.ljust(displayName, 19, " ").toUpperCase().substring(0, 19);
} }
String getCondition(String icaoCode, String key) { String getCondition(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) Request request = new Request.Builder()
.GET() .url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); try (Response response = client.newCall(request).execute()) {
if (Response.statusCode() != 200) { if (!response.isSuccessful()) {
return "NO REPORT"; return "NO REPORT";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
return utl.getCondition(JSONResponse.getInt("iconCodeExtend")); String responseBody = response.body().string();
JSONObject jsonResponse = new JSONObject(responseBody);
return utl.getCondition(jsonResponse.getInt("iconCodeExtend"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return "NO REPORT"; return "NO REPORT";
} }
} }
String getTemperature(String icaoCode, String key) { String getTemperature(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/observations/current?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) Request request = new Request.Builder()
.GET() .url(url)
.get()
.header("Accept", "application/json") .header("Accept", "application/json")
.build(); .build();
try {
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString()); try (Response response = client.newCall(request).execute()) {
if (Response.statusCode() != 200) { if (!response.isSuccessful()) {
return " "; return " ";
} }
String ResponseBody = Response.body();
JSONObject JSONResponse = new JSONObject(ResponseBody);
return utl.rjust(Integer.toString(JSONResponse.getInt("temperature")), 3, " "); String responseBody = response.body().string();
JSONObject jsonResponse = new JSONObject(responseBody);
return utl.rjust(Integer.toString(jsonResponse.getInt("temperature")), 3, " ");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return " "; return " ";
} }
} }
public void run() { public void run() {
ArrayList<String> regConNames = new ArrayList<>(); ArrayList<String> regConNames = new ArrayList<>();
regConNames.addAll(Main.regConNames); regConNames.addAll(Main.regConNames);
ArrayList<String> regConIcaos = new ArrayList<>(); ArrayList<String> regConIcaos = new ArrayList<>();
regConIcaos.addAll(Main.regConIcaos); regConIcaos.addAll(Main.regConIcaos);
String key = Main.key; String key = Main.key;
Main.regionalConditions.locName.clear();
Main.regionalConditions.temperature.clear();
Main.regionalConditions.condition.clear();
for (int i = 0; i < regConIcaos.size(); i++) { for (int i = 0; i < regConIcaos.size(); i++) {
Main.regionalConditions.locName.add(getLocName(regConNames.get(i))); Main.regionalConditions.locName.add(getLocName(regConNames.get(i)));
Main.regionalConditions.temperature.add(getTemperature(regConIcaos.get(i), key)); Main.regionalConditions.temperature.add(getTemperature(regConIcaos.get(i), key));
@@ -4,101 +4,121 @@ import org.json.JSONObject;
import util.Utilities; import util.Utilities;
import java.net.URI; import okhttp3.OkHttpClient;
import java.net.http.HttpClient; import okhttp3.Request;
import java.net.http.HttpRequest; import okhttp3.Response;
import java.net.http.HttpResponse;
import java.time.ZonedDateTime;
import java.util.ArrayList; import java.util.ArrayList;
public class RegionalForecast extends Thread { public class RegionalForecast extends Thread {
private final OkHttpClient client = new OkHttpClient();
ArrayList<String> locName = new ArrayList<>(); ArrayList<String> locName = new ArrayList<>();
ArrayList<String> condition = new ArrayList<>(); ArrayList<String> condition = new ArrayList<>();
ArrayList<String> low = new ArrayList<>(); ArrayList<String> low = new ArrayList<>();
ArrayList<String> high = new ArrayList<>(); ArrayList<String> high = new ArrayList<>();
String first;
Utilities utl = new Utilities(); Utilities utl = new Utilities();
String getLocName(String displayName){ String getLocName(String displayName){
return utl.ljust(displayName, 14, " ").substring(0, 14); return utl.ljust(displayName, 14, " ").toUpperCase().substring(0, 14);
} }
String getCondition(String icaoCode, String key) { String getCondition(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) Request request = new Request.Builder()
.GET() .url(url)
.header("Accept", "application/json") .get()
.build(); .header("Accept", "application/json")
try { .build();
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) { try (Response response = client.newCall(request).execute()) {
return "NO REPORT"; if (!response.isSuccessful()) {
} return "NO REPORT";
String ResponseBody = Response.body(); }
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0); String responseBody = response.body().string();
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0; JSONObject jsonResponse = new JSONObject(responseBody);
JSONObject dpData = jsonResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0;
return utl.getForecast(dpData.getJSONArray("iconCodeExtend").getInt(bump));
} catch (Exception e) {
e.printStackTrace();
return "NO REPORT";
}
}
return utl.getForecast(dpData.getJSONArray("iconCodeExtend").getInt(bump));
} catch (Exception e) {
e.printStackTrace();
return "NO REPORT";
}
}
String getLow(String icaoCode, String key) { String getLow(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) Request request = new Request.Builder()
.GET() .url(url)
.header("Accept", "application/json") .get()
.build(); .header("Accept", "application/json")
try { .build();
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) { try (Response response = client.newCall(request).execute()) {
return " "; if (!response.isSuccessful()) {
} return " ";
String ResponseBody = Response.body(); }
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0); String responseBody = response.body().string();
JSONObject jsonResponse = new JSONObject(responseBody);
JSONObject dpData = jsonResponse.getJSONArray("daypart").getJSONObject(0);
return utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(1)), 3, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
return utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(1)), 3, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
String getHigh(String icaoCode, String key) { String getHigh(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) Request request = new Request.Builder()
.GET() .url(url)
.header("Accept", "application/json") .get()
.build(); .header("Accept", "application/json")
try { .build();
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) { try (Response response = client.newCall(request).execute()) {
return " "; if (!response.isSuccessful()) {
} return " ";
String ResponseBody = Response.body(); }
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0); String responseBody = response.body().string();
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0; JSONObject jsonResponse = new JSONObject(responseBody);
JSONObject dpData = jsonResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0;
return utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(bump)), 3, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
return utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(bump)), 3, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
public void run() { public void run() {
ArrayList<String> regForNames = new ArrayList<>(); ArrayList<String> regForNames = new ArrayList<>();
regForNames.addAll(Main.regForNames); regForNames.addAll(Main.regForNames);
ArrayList<String> regForIcaos = new ArrayList<>(); ArrayList<String> regForIcaos = new ArrayList<>();
regForIcaos.addAll(Main.regForIcaos); regForIcaos.addAll(Main.regForIcaos);
String key = Main.key; String key = Main.key;
Main.regionalForecast.locName.clear();
Main.regionalForecast.condition.clear();
Main.regionalForecast.low.clear();
Main.regionalForecast.high.clear();
for (int i = 0; i < regForIcaos.size(); i++) { for (int i = 0; i < regForIcaos.size(); i++) {
Main.regionalForecast.locName.add(getLocName(regForNames.get(i))); Main.regionalForecast.locName.add(getLocName(regForNames.get(i)));
Main.regionalForecast.condition.add(getCondition(regForIcaos.get(i), key)); Main.regionalForecast.condition.add(getCondition(regForIcaos.get(i), key));
Main.regionalForecast.low.add(getLow(regForIcaos.get(i), key)); Main.regionalForecast.low.add(getLow(regForIcaos.get(i), key));
Main.regionalForecast.high.add(getHigh(regForIcaos.get(i), key)); Main.regionalForecast.high.add(getHigh(regForIcaos.get(i), key));
} }
int hr = ZonedDateTime.now(Main.timeZone).getHour();
Main.regionalForecast.first = hr >= 4 && hr < 16 ? "H" : "L";
} }
} }
@@ -21,10 +21,8 @@ import java.io.File;
import java.awt.Color; import java.awt.Color;
import java.awt.Image; import java.awt.Image;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
public class SlidesRunner extends Scene { public class SlidesRunner extends Scene {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("h:mm:ss a"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("h:mm:ss a");
@@ -60,9 +58,8 @@ public class SlidesRunner extends Scene {
GameObject cBumperTwo; GameObject cBumperTwo;
Utilities utl = new Utilities(); Utilities utl = new Utilities();
LocalDateTime now = LocalDateTime.now(); ZonedDateTime now = ZonedDateTime.now(Main.timeZone);
ZonedDateTime today = ZonedDateTime.now(); final String prefix = now.format(DateTimeFormatter.ofPattern("E MMM"));
final String prefix = today.format(DateTimeFormatter.ofPattern("E MMM"));
//slide line variables //slide line variables
ArrayList<String> ccMainLines = new ArrayList<>(); ArrayList<String> ccMainLines = new ArrayList<>();
@@ -94,6 +91,9 @@ public class SlidesRunner extends Scene {
ArrayList<String> olMainLines = new ArrayList<>(); ArrayList<String> olMainLines = new ArrayList<>();
private GameObject[] olPool = new GameObject[288]; private GameObject[] olPool = new GameObject[288];
ArrayList<String> tiMainLines = new ArrayList<>();
private GameObject[] tiPool = new GameObject[288];
ArrayList<String> travelMainLines = new ArrayList<>(); ArrayList<String> travelMainLines = new ArrayList<>();
private GameObject[] tfPool = new GameObject[864]; private GameObject[] tfPool = new GameObject[864];
@@ -113,9 +113,11 @@ public class SlidesRunner extends Scene {
private boolean poolsInit = false; private boolean poolsInit = false;
private boolean slideInit = false; private boolean slideInit = false;
private int tinterval = 0;
GameObject tBanner; GameObject tBanner;
TravelForecast tfData; TravelForecast tfData;
int travelOffset = 0; float travelOffset = 0.0f;
boolean travelDataInit = false; boolean travelDataInit = false;
boolean travelForecastActive = false; boolean travelForecastActive = false;
@@ -141,7 +143,8 @@ public class SlidesRunner extends Scene {
float slideLength = 600.0f;//length in frames float slideLength = 600.0f;//length in frames
int slideIdx = 0; int slideIdx = 0;
String[] slideLineup; ArrayList<String> slideLineup;
ArrayList<Float> slideDurations;
boolean loop; boolean loop;
boolean ending = false; boolean ending = false;
int slideRounds = 0; int slideRounds = 0;
@@ -160,7 +163,23 @@ public class SlidesRunner extends Scene {
crawlingText = Main.adCrawl + " "; crawlingText = Main.adCrawl + " ";
loop = Main.loopSlides; loop = Main.loopSlides;
slideLineup = Main.slidesList;
try {
slideLineup = utl.loadSegments(Main.selectedFlavor);
} catch (IOException e) {
System.err.println("Exception loading flavor segments");
System.exit(100);
e.printStackTrace();
}
try {
slideDurations = utl.loadDurations(Main.selectedFlavor);
} catch (IOException e) {
System.err.println("Exception loading flavor durations");
System.exit(101);
e.printStackTrace();
}
if (Main.greenScreen) { if (Main.greenScreen) {
backgroundColor = greenScreen; backgroundColor = greenScreen;
} }
@@ -285,18 +304,23 @@ public class SlidesRunner extends Scene {
olPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); olPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1)));
} }
for (int i = 0; i < tiPool.length; i++) {
tiPool[i] = new GameObject("tiPool" + i, new Transform(new Vector2f()), 0);
tiPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1)));
}
for (int i = 0; i < tfPool.length; i++) { for (int i = 0; i < tfPool.length; i++) {
tfPool[i] = new GameObject("tfPool" + i, new Transform(new Vector2f()), 0); tfPool[i] = new GameObject("tfPool" + i, new Transform(new Vector2f()), 0);
tfPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); tfPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1)));
} }
for (int i = 0; i < dtPool.length; i++) { for (int i = 0; i < dtPool.length; i++) {
dtPool[i] = new GameObject("tfPool" + i, new Transform(new Vector2f()), 2); dtPool[i] = new GameObject("dtPool" + i, new Transform(new Vector2f()), 2);
dtPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); dtPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1)));
} }
for (int i = 0; i < ctPool.length; i++) { for (int i = 0; i < ctPool.length; i++) {
ctPool[i] = new GameObject("tfPool" + i, new Transform(new Vector2f()), 2); ctPool[i] = new GameObject("ctPool" + i, new Transform(new Vector2f()), 2);
ctPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1))); ctPool[i].addComponent(new SpriteRenderer(new Vector4f(1,1,1,1)));
} }
@@ -371,7 +395,7 @@ public class SlidesRunner extends Scene {
round++; round++;
if (round >= slideRounds) { if (round >= slideRounds) {
slideIdx++; slideIdx++;
if (slideIdx >= slideLineup.length) { if (slideIdx >= slideLineup.size()) {
slideIdx = 0; slideIdx = 0;
if (!loop) { if (!loop) {
ending = true; ending = true;
@@ -398,9 +422,18 @@ public class SlidesRunner extends Scene {
//Main.settingsWindow.setVisible(true); //Main.settingsWindow.setVisible(true);
} }
slideLength = slideDurations.get(slideIdx);
slideChooser(); slideChooser();
if (travelForecastActive) { if (travelForecastActive) {
if (Window.secFrameCount % 2 == 0) travelOffset--; if (Window.secFrameCount % 2 == 0) {
travelOffset--;
tinterval++;
if (tinterval == 3) {
travelOffset--;
tinterval = 0;
}
}
travelForecast(); travelForecast();
} }
@@ -511,8 +544,7 @@ public class SlidesRunner extends Scene {
} }
public void dateTime() { public void dateTime() {
now = LocalDateTime.now(); now = ZonedDateTime.now(Main.timeZone);
today = ZonedDateTime.now();
dateLine = utl.ljust(String.format("%s %2d", prefix, now.getDayOfMonth()).toUpperCase(), 10, " ") + utl.ljust(" ", 11, " ") + utl.rjust(now.format(formatter), 11, " "); dateLine = utl.ljust(String.format("%s %2d", prefix, now.getDayOfMonth()).toUpperCase(), 10, " ") + utl.ljust(" ", 11, " ") + utl.rjust(now.format(formatter), 11, " ");
@@ -577,18 +609,23 @@ public class SlidesRunner extends Scene {
CurrentConditions ctData = Main.currentConditions; CurrentConditions ctData = Main.currentConditions;
tickerLines.clear(); tickerLines.clear();
tickerLines.add(utl.ljust(ctData.locName, 32, " "));
tickerLines.add(utl.ljust(ctData.condition, 32, " ")); if (ctData.condition.equals("NO CURRENT REPORT")) {
tickerLines.add(utl.ljust(ctData.temperature + " " + ctData.feelsLike, 32, " ")); tickerLines.add(utl.ljust(ctData.locName, 32, " "));
tickerLines.add(utl.ljust(ctData.humidity + " " + ctData.dewPoint, 32, " ")); tickerLines.add(utl.ljust(ctData.condition, 32, " "));
tickerLines.add(utl.ljust(ctData.pressure, 32, " ")); } else {
tickerLines.add(utl.ljust(ctData.wind + " " + ctData.gusts, 32, " ")); tickerLines.add(utl.ljust(ctData.locName, 32, " "));
tickerLines.add(utl.ljust(ctData.visibility + " " + ctData.ceiling, 32, " ")); tickerLines.add(utl.ljust(ctData.condition, 32, " "));
tickerLines.add(utl.ljust(ctData.precip, 32, " ")); tickerLines.add(utl.ljust(ctData.temperature + " " + ctData.feelsLike, 32, " "));
tickerLines.add(utl.ljust(ctData.humidity + " " + ctData.dewPoint, 32, " "));
tickerLines.add(utl.ljust(ctData.pressure, 32, " "));
tickerLines.add(utl.ljust(ctData.wind + " " + ctData.gusts, 32, " "));
tickerLines.add(utl.ljust(ctData.visibility + " " + ctData.ceiling, 32, " "));
tickerLines.add(utl.ljust(ctData.precip, 32, " "));
}
} }
public void currentConditions() { public void currentConditions() {
slideRounds = 0; slideRounds = 0;
slideLength = 600.0f;
this.addGameObjectToScene(bg); this.addGameObjectToScene(bg);
if (!slideInit) { if (!slideInit) {
@@ -639,7 +676,6 @@ public class SlidesRunner extends Scene {
public void hourlyObservations() { public void hourlyObservations() {
slideRounds = 0; slideRounds = 0;
slideLength = 600.0f;
this.addGameObjectToScene(bg); this.addGameObjectToScene(bg);
if (!slideInit) { if (!slideInit) {
@@ -688,7 +724,6 @@ public class SlidesRunner extends Scene {
public void regionalConditions() { public void regionalConditions() {
slideRounds = 0; slideRounds = 0;
slideLength = 600.0f;
this.addGameObjectToScene(bg); this.addGameObjectToScene(bg);
if (!slideInit) { if (!slideInit) {
@@ -738,7 +773,6 @@ public class SlidesRunner extends Scene {
public void localForecast() { public void localForecast() {
slideRounds = 3; slideRounds = 3;
slideLength = 600.0f;
this.addGameObjectToScene(bg); this.addGameObjectToScene(bg);
if (!slideInit) { if (!slideInit) {
@@ -761,7 +795,7 @@ public class SlidesRunner extends Scene {
} }
int wordlength = lfData.bulletin.get(i).length(); int wordlength = lfData.bulletin.get(i).length();
if (wordlength + sb.length() + 1 <= 30) { if (wordlength + sb.length() + 1 <= 30) {
if (!sb.isEmpty()) {sb.append(" ");} if (!(sb.length() == 0)) {sb.append(" ");}
sb.append(lfData.bulletin.get(i)); sb.append(lfData.bulletin.get(i));
} else { } else {
i--; i--;
@@ -779,7 +813,7 @@ public class SlidesRunner extends Scene {
for (int i = 0; i <= lfData.forecastOne.size()-1; i++) { for (int i = 0; i <= lfData.forecastOne.size()-1; i++) {
int wordlength = lfData.forecastOne.get(i).length(); int wordlength = lfData.forecastOne.get(i).length();
if (wordlength + sb.length() + 1 <= 32) { if (wordlength + sb.length() + 1 <= 32) {
if (!sb.isEmpty()) {sb.append(" ");} if (!(sb.length() == 0)) {sb.append(" ");}
sb.append(lfData.forecastOne.get(i)); sb.append(lfData.forecastOne.get(i));
} else { } else {
i--; i--;
@@ -793,7 +827,7 @@ public class SlidesRunner extends Scene {
for (int i = 0; i <= lfData.forecastTwo.size()-1; i++) { for (int i = 0; i <= lfData.forecastTwo.size()-1; i++) {
int wordlength = lfData.forecastTwo.get(i).length(); int wordlength = lfData.forecastTwo.get(i).length();
if (wordlength + sb.length() + 1 <= 32) { if (wordlength + sb.length() + 1 <= 32) {
if (!sb.isEmpty()) {sb.append(" ");} if (!(sb.length() == 0)) {sb.append(" ");}
sb.append(lfData.forecastTwo.get(i)); sb.append(lfData.forecastTwo.get(i));
} else { } else {
i--; i--;
@@ -807,7 +841,7 @@ public class SlidesRunner extends Scene {
for (int i = 0; i <= lfData.forecastThree.size()-1; i++) { for (int i = 0; i <= lfData.forecastThree.size()-1; i++) {
int wordlength = lfData.forecastThree.get(i).length(); int wordlength = lfData.forecastThree.get(i).length();
if (wordlength + sb.length() + 1 <= 32) { if (wordlength + sb.length() + 1 <= 32) {
if (!sb.isEmpty()) {sb.append(" ");} if (!(sb.length() == 0)) {sb.append(" ");}
sb.append(lfData.forecastThree.get(i)); sb.append(lfData.forecastThree.get(i));
} else { } else {
i--; i--;
@@ -926,7 +960,6 @@ public class SlidesRunner extends Scene {
public void almanac() { public void almanac() {
slideRounds = 0; slideRounds = 0;
slideLength = 600.0f;
this.addGameObjectToScene(bg); this.addGameObjectToScene(bg);
if (!slideInit) { if (!slideInit) {
@@ -979,7 +1012,6 @@ public class SlidesRunner extends Scene {
public void regionalForecast() { public void regionalForecast() {
slideRounds = 0; slideRounds = 0;
slideLength = 600.0f;
this.addGameObjectToScene(bg); this.addGameObjectToScene(bg);
if (!slideInit) { if (!slideInit) {
@@ -988,11 +1020,21 @@ public class SlidesRunner extends Scene {
rfMainLines.clear(); rfMainLines.clear();
rfMainLines.add(" FORECAST ACROSS THE REGION "); rfMainLines.add(" FORECAST ACROSS THE REGION ");
rfMainLines.add("CITY WEATHER LOW HI");
for (int i = 0; i < rfData.locName.size(); i++) { if (rfData.first.equals("L")) {
rfMainLines.add(utl.ljust(rfData.locName.get(i), 14, " ") + " " + utl.ljust(rfData.condition.get(i), 10, " ") + rfData.low.get(i) + " " + rfData.high.get(i)); rfMainLines.add("CITY WEATHER LOW HI");
for (int i = 0; i < rfData.locName.size(); i++) {
rfMainLines.add(utl.ljust(rfData.locName.get(i), 14, " ") + " " + utl.ljust(rfData.condition.get(i), 10, " ") + rfData.low.get(i) + " " + rfData.high.get(i));
}
} else if (rfData.first.equals("H")) {
rfMainLines.add("CITY WEATHER HI LOW");
for (int i = 0; i < rfData.locName.size(); i++) {
rfMainLines.add(utl.ljust(rfData.locName.get(i), 14, " ") + " " + utl.ljust(rfData.condition.get(i), 10, " ") + rfData.high.get(i) + " " + rfData.low.get(i));
}
} }
slideInit = true; slideInit = true;
} }
@@ -1029,7 +1071,6 @@ public class SlidesRunner extends Scene {
public void extendedForecast() { public void extendedForecast() {
slideRounds = 0; slideRounds = 0;
slideLength = 600.0f;
this.addGameObjectToScene(bg); this.addGameObjectToScene(bg);
if (!slideInit) { if (!slideInit) {
@@ -1081,7 +1122,6 @@ public class SlidesRunner extends Scene {
public void outlook() { public void outlook() {
slideRounds = 0; slideRounds = 0;
slideLength = 600.0f;
this.addGameObjectToScene(bg); this.addGameObjectToScene(bg);
if (!slideInit) { if (!slideInit) {
@@ -1089,24 +1129,14 @@ public class SlidesRunner extends Scene {
olMainLines.clear(); olMainLines.clear();
olMainLines.add(" NAT'L WEATHER SERVICE OUTLOOK ");
olMainLines.add(utl.ljust(" ", 32, " "));//half space
olMainLines.add(utl.cjust(oData.month, 32, " "));
olMainLines.add(utl.ljust(" ", 32, " ")); olMainLines.add(utl.ljust(" ", 32, " "));
olMainLines.add(utl.ljust(" ", 32, " "));
StringBuilder sb = new StringBuilder(); olMainLines.add(" 30 DAY OUTLOOK ");
for (int i = 0; i <= oData.outlook.size()-1; i++) { olMainLines.add(oData.month);
int cwordlength = oData.outlook.get(i).length(); olMainLines.add(utl.ljust(" ", 32, " "));
if (cwordlength + sb.length() + 1 <= 32) { olMainLines.add("TEMPERATURES: " + oData.temperature);
if (!sb.isEmpty()) {sb.append(" ");} olMainLines.add(utl.ljust(" ", 32, " "));
sb.append(oData.outlook.get(i)); olMainLines.add("PRECIPITATION: " + oData.precipitation);
} else {
i--;
olMainLines.add(utl.ljust(sb.toString(), 32, " "));
sb.setLength(0);
}
}
olMainLines.add(utl.ljust(sb.toString(), 32, " "));
slideInit = true; slideInit = true;
} }
@@ -1116,7 +1146,7 @@ public class SlidesRunner extends Scene {
int poolIdx = 0; int poolIdx = 0;
for (int row = 0; row < olMainLines.size(); row++) { for (int row = 0; row < olMainLines.size(); row++) {
int lineHeight = row == 1 ? 22 : 40; int lineHeight = 40;
String line = olMainLines.get(row); String line = olMainLines.get(row);
for (int i = 0; i < line.length(); i ++) { for (int i = 0; i < line.length(); i ++) {
if (poolIdx >= olPool.length) break; if (poolIdx >= olPool.length) break;
@@ -1141,23 +1171,97 @@ public class SlidesRunner extends Scene {
textY += lineHeight; textY += lineHeight;
} }
} }
public void tides() {
slideRounds = 0;
this.addGameObjectToScene(bg);
if (!slideInit) {
Tides tiData = Main.tides;
tiMainLines.clear();
tiMainLines.add(" LOCAL TIDE INFORMATION ");
tiMainLines.add(utl.ljust(" ", 32, " "));//half space
tiMainLines.add(tiData.locName.get(0));
tiMainLines.add("HIGHS: " + tiData.highTide.get(0));
tiMainLines.add("LOWS: " + tiData.lowTide.get(0));
tiMainLines.add(tiData.locName.get(1));
tiMainLines.add("HIGHS: " + tiData.highTide.get(1));
tiMainLines.add("LOWS: " + tiData.lowTide.get(1));
tiMainLines.add(" SUNRISE" + tiData.sunrise + " SET" + tiData.sunset + " ");
slideInit = true;
}
int textX = 81;
int textY = 44;
int poolIdx = 0;
for (int row = 0; row < tiMainLines.size(); row++) {
int lineHeight = row == 1 ? 22 : 40;
String line = tiMainLines.get(row);
for (int i = 0; i < line.length(); i ++) {
if (poolIdx >= tiPool.length) break;
char c = line.charAt(i);
GameObject go = tiPool[poolIdx++];
go.transform.position.set(textX, textY);
go.transform.scale.set(18, 32);
SpriteRenderer sr = go.getComponent(SpriteRenderer.class);
sr.setSprite(sprites.getSprite(utl.getMainChar(c)));
this.addGameObjectToScene(go);
if (i % 2 != 0) textX++;
textX += 17;
}
textX = 81;
textY += lineHeight;
}
}
public void airQuality() {
slideRounds = 0;
this.addGameObjectToScene(bg);
if (!slideInit) {
slideInit = true;
}
}
public void travelForecast() { public void travelForecast() {
slideLength = 3600.0f;
travelForecastActive = true; travelForecastActive = true;
this.addGameObjectToScene(travelBg); this.addGameObjectToScene(travelBg);
if (!travelDataInit) { if (!travelDataInit) {
tfData = Main.travelForecast; tfData = Main.travelForecast;
travelMainLines.clear(); travelMainLines.clear();
travelMainLines.add(" TRAVEL CITIES FORECAST "); travelMainLines.add(" TRAVEL CITIES FORECAST ");
travelMainLines.add(utl.ljust(" ", 32, " ")); travelMainLines.add(utl.ljust(" ", 32, " "));
travelMainLines.add("CITY WEATHER LOW HI");
for (int i = 0; i < tfData.locName.size(); i++) { if (tfData.first.equals("L")) {
travelMainLines.add(utl.ljust(tfData.locName.get(i), 15, " ") + travelMainLines.add("CITY WEATHER LOW HI");
for (int i = 0; i < tfData.locName.size(); i++) {
travelMainLines.add(utl.ljust(tfData.locName.get(i), 15, " ") +
utl.ljust(tfData.condition.get(i), 10, " ") + utl.ljust(tfData.condition.get(i), 10, " ") +
utl.rjust(tfData.low.get(i), 3, " ") + utl.rjust(tfData.low.get(i), 3, " ") +
utl.rjust(tfData.high.get(i), 4, " ")); utl.rjust(tfData.high.get(i), 4, " "));
}
} else if ((tfData.first.equals("H"))) {
travelMainLines.add("CITY WEATHER HI LOW");
for (int i = 0; i < tfData.locName.size(); i++) {
travelMainLines.add(utl.ljust(tfData.locName.get(i), 15, " ") +
utl.ljust(tfData.condition.get(i), 10, " ") +
utl.rjust(tfData.high.get(i), 3, " ") +
utl.rjust(tfData.low.get(i), 4, " "));
}
} }
travelDataInit = true; travelDataInit = true;
travelOffset = 0; travelOffset = 0;
} }
@@ -1263,7 +1367,7 @@ public class SlidesRunner extends Scene {
public void slideChooser() { public void slideChooser() {
//draw slide //draw slide
String slide = slideLineup[slideIdx]; String slide = slideLineup.get(slideIdx);
//System.out.println(slide); //System.out.println(slide);
switch (slide) { switch (slide) {
case "currentConditions": case "currentConditions":
@@ -1279,7 +1383,11 @@ public class SlidesRunner extends Scene {
localForecast(); localForecast();
break; break;
case "almanac": case "almanac":
almanac(); if (Main.tidesEnabled) {
tides();
} else {
almanac();
}
break; break;
case "regionalForecast": case "regionalForecast":
regionalForecast(); regionalForecast();
@@ -0,0 +1,118 @@
package WS3000.weatherstar3000;
import util.Utilities;
import org.json.JSONArray;
import org.json.JSONObject;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import java.util.ArrayList;
import java.time.ZonedDateTime;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
public class Tides extends Thread {
private final OkHttpClient client = new OkHttpClient();
Utilities utl = new Utilities();
ArrayList<String> locName = new ArrayList<>();
ArrayList<String> highTide = new ArrayList<>();
ArrayList<String> lowTide = new ArrayList<>();
String sunrise;
String sunset;
DateTimeFormatter tideDateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
DateTimeFormatter tideTimeFormatter = DateTimeFormatter.ofPattern("h:mma E", Locale.ENGLISH);
String getLocName(String displayName) {
return utl.cjust(displayName, 32, " ").toUpperCase().substring(0, 32);
}
String getTides(String station, String tide) {
String url = "https://api.tidesandcurrents.noaa.gov/api/prod/datagetter?begin_date=" + ZonedDateTime.now(Main.timeZone).format(tideDateFormatter) + "&end_date=" + ZonedDateTime.now(Main.timeZone).plusDays(1).format(tideDateFormatter) + "&station=" + station + "&product=predictions&datum=MLLW&time_zone=lst_ldt&interval=hilo&units=english&application=DataAPI_Sample&format=json";
Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json")
.build();
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
return " ";
}
String responseBody = response.body().string();
JSONArray predictions = new JSONObject(responseBody).getJSONArray("predictions");
StringBuilder sb = new StringBuilder();
int j = 0;
for (int i = 0; i < predictions.length(); i++) {
if (predictions.getJSONObject(i).getString("type").equals(tide)) {
sb.append(utl.rjust(LocalDateTime.parse(predictions.getJSONObject(i).getString("t"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")).format(tideTimeFormatter).toUpperCase(Locale.ENGLISH), 11, " "));
if (j < 1) sb.append(" ");
j++;
if (j == 2) break;
}
}
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
String getSunData(String icaoCode, String key, String type) {
String url = "https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
Request request = new Request.Builder()
.url(url)
.get()
.header("Accept", "application/json")
.build();
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
return " ";
}
String responseBody = response.body().string();
JSONObject jsonResponse = new JSONObject(responseBody);
String time = jsonResponse.getJSONArray(type).getString(0);
int hour = Integer.parseInt(time.substring(11, 13));
int dispHour = hour > 12 ? hour - 12 : hour;
String minutes = time.substring(14, 16);
String part = hour < 12 ? "AM" : "PM";
return utl.rjust(dispHour + ":" + minutes + part, 7, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
public void run() {
ArrayList<String> tideIDs = new ArrayList<>();
tideIDs.addAll(Main.tideIDs);
ArrayList<String> tideNames = new ArrayList<>();
tideNames.addAll(Main.tideNames);
String key = Main.key;
Main.tides.highTide.clear();
Main.tides.lowTide.clear();
for (int i = 0; i < tideIDs.size(); i++) {
Main.tides.locName.add(getLocName(Main.tideNames.get(i)));
Main.tides.highTide.add(getTides(Main.tideIDs.get(i), "H"));
Main.tides.lowTide.add(getTides(Main.tideIDs.get(i), "L"));
}
Main.tides.sunrise = getSunData(Main.mainIcao, key, "sunriseTimeLocal");
Main.tides.sunset = getSunData(Main.mainIcao, key, "sunsetTimeLocal");
}
}
@@ -1,9 +1,10 @@
package WS3000.weatherstar3000; package WS3000.weatherstar3000;
import java.net.URI; import okhttp3.OkHttpClient;
import java.net.http.HttpClient; import okhttp3.Request;
import java.net.http.HttpRequest; import okhttp3.Response;
import java.net.http.HttpResponse;
import java.time.ZonedDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@@ -12,93 +13,112 @@ import org.json.JSONObject;
import util.Utilities; import util.Utilities;
public class TravelForecast extends Thread { public class TravelForecast extends Thread {
private final OkHttpClient client = new OkHttpClient();
ArrayList<String> locName = new ArrayList<>(); ArrayList<String> locName = new ArrayList<>();
ArrayList<String> condition = new ArrayList<>(); ArrayList<String> condition = new ArrayList<>();
ArrayList<String> low = new ArrayList<>(); ArrayList<String> low = new ArrayList<>();
ArrayList<String> high = new ArrayList<>(); ArrayList<String> high = new ArrayList<>();
Utilities utl = new Utilities(); Utilities utl = new Utilities();
String first;
ArrayList<String> tForNames = new ArrayList<>(Arrays.asList("ATLANTA", "BISMARCK", "BOISE", "BOSTON", "BUFFALO", "CHICAGO", "CINCINNATI", "DALLAS", "DENVER", "DETROIT", "KANSAS CITY", "LOS ANGELES", "MINNEAPOLIS", "NASHVILLE", "NEW ORLEANS", "NEW YORK CITY", "PHOENIX", "PORTLAND", "RALEIGH", "RAPID CITY", "SACRAMENTO", "SALT LAKE CITY", "TAMPA", "WASHINGTON, DC")); ArrayList<String> tForNames = new ArrayList<>(Arrays.asList("ATLANTA", "BISMARCK", "BOISE", "BOSTON", "BUFFALO", "CHICAGO", "CINCINNATI", "DALLAS", "DENVER", "DETROIT", "KANSAS CITY", "LOS ANGELES", "MINNEAPOLIS", "NASHVILLE", "NEW ORLEANS", "NEW YORK CITY", "PHOENIX", "PORTLAND", "RALEIGH", "RAPID CITY", "SACRAMENTO", "SALT LAKE CITY", "TAMPA", "WASHINGTON, DC"));
ArrayList<String> tForIcaos = new ArrayList<>(Arrays.asList("KATL", "KBIS", "KBOI", "KBOS", "KBUF", "KORD", "KCVG", "KDAL", "KDEN", "KDTW", "KMCI", "KLAX", "KMSP", "KDNA", "KMSY", "KLGA", "KPHX", "KPDX", "KRDU", "KRAP", "KSMF", "KSLC", "KTPA", "KDCA")); ArrayList<String> tForIcaos = new ArrayList<>(Arrays.asList("KATL", "KBIS", "KBOI", "KBOS", "KBUF", "KORD", "KCVG", "KDAL", "KDEN", "KDTW", "KMCI", "KLAX", "KMSP", "KDNA", "KMSY", "KLGA", "KPHX", "KPDX", "KRDU", "KRAP", "KSMF", "KSLC", "KTPA", "KDCA"));
String getLocName(String displayName){ String getLocName(String displayName){
return utl.ljust(displayName, 14, " ").substring(0, 14); return utl.ljust(displayName, 14, " ").toUpperCase().substring(0, 14);
} }
String getCondition(String icaoCode, String key) { String getCondition(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) Request request = new Request.Builder()
.GET() .url(url)
.header("Accept", "application/json") .get()
.build(); .header("Accept", "application/json")
try { .build();
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) { try (Response response = client.newCall(request).execute()) {
return "NO REPORT"; if (!response.isSuccessful()) {
} return "NO REPORT";
String ResponseBody = Response.body(); }
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0); String responseBody = response.body().string();
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0; JSONObject jsonResponse = new JSONObject(responseBody);
JSONObject dpData = jsonResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0;
return utl.getForecast(dpData.getJSONArray("iconCodeExtend").getInt(bump));
} catch (Exception e) {
e.printStackTrace();
return "NO REPORT";
}
}
return utl.getForecast(dpData.getJSONArray("iconCodeExtend").getInt(bump));
} catch (Exception e) {
e.printStackTrace();
return "NO REPORT";
}
}
String getLow(String icaoCode, String key) { String getLow(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) Request request = new Request.Builder()
.GET() .url(url)
.header("Accept", "application/json") .get()
.build(); .header("Accept", "application/json")
try { .build();
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) { try (Response response = client.newCall(request).execute()) {
return " "; if (!response.isSuccessful()) {
} return " ";
String ResponseBody = Response.body(); }
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0); String responseBody = response.body().string();
JSONObject jsonResponse = new JSONObject(responseBody);
JSONObject dpData = jsonResponse.getJSONArray("daypart").getJSONObject(0);
return utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(1)), 3, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
return utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(1)), 3, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
String getHigh(String icaoCode, String key) { String getHigh(String icaoCode, String key) {
HttpClient Client = HttpClient.newBuilder().build(); String url = "https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key;
HttpRequest Request = HttpRequest.newBuilder()
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key)) Request request = new Request.Builder()
.GET() .url(url)
.header("Accept", "application/json") .get()
.build(); .header("Accept", "application/json")
try { .build();
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
if (Response.statusCode() != 200) { try (Response response = client.newCall(request).execute()) {
return " "; if (!response.isSuccessful()) {
} return " ";
String ResponseBody = Response.body(); }
JSONObject JSONResponse = new JSONObject(ResponseBody);
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0); String responseBody = response.body().string();
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0; JSONObject jsonResponse = new JSONObject(responseBody);
JSONObject dpData = jsonResponse.getJSONArray("daypart").getJSONObject(0);
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0;
return utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(bump)), 3, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
return utl.rjust(Integer.toString(dpData.getJSONArray("temperature").getInt(bump)), 3, " ");
} catch (Exception e) {
e.printStackTrace();
return " ";
}
}
public void run() { public void run() {
String key = Main.key; String key = Main.key;
Main.travelForecast.locName.clear();
Main.travelForecast.condition.clear();
Main.travelForecast.high.clear();
Main.travelForecast.low.clear();
for (int i = 0; i < tForIcaos.size(); i++) { for (int i = 0; i < tForIcaos.size(); i++) {
Main.travelForecast.locName.add(getLocName(tForNames.get(i))); Main.travelForecast.locName.add(getLocName(tForNames.get(i)));
Main.travelForecast.condition.add(getCondition(tForIcaos.get(i), key)); Main.travelForecast.condition.add(getCondition(tForIcaos.get(i), key));
Main.travelForecast.low.add(getLow(tForIcaos.get(i), key)); Main.travelForecast.low.add(getLow(tForIcaos.get(i), key));
Main.travelForecast.high.add(getHigh(tForIcaos.get(i), key)); Main.travelForecast.high.add(getHigh(tForIcaos.get(i), key));
} }
int hr = ZonedDateTime.now(Main.timeZone).getHour();
Main.travelForecast.first = hr >= 4 && hr < 16 ? "H" : "L";
} }
} }
+10 -2
View File
@@ -5,6 +5,7 @@ import static org.lwjgl.opengl.ARBTextureRectangle.*;
import static org.lwjgl.stb.STBImage.*; import static org.lwjgl.stb.STBImage.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.*; import java.nio.*;
@@ -61,10 +62,17 @@ public class Texture {
} }
// Read bytes from the JAR stream into a native ByteBuffer // Read bytes from the JAR stream into a native ByteBuffer
byte[] bytes = is.readAllBytes(); ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
buffer.flush();
byte[] bytes = buffer.toByteArray();
ByteBuffer nativeBuffer = BufferUtils.createByteBuffer(bytes.length); ByteBuffer nativeBuffer = BufferUtils.createByteBuffer(bytes.length);
nativeBuffer.put(bytes); nativeBuffer.put(bytes);
nativeBuffer.flip(); ((java.nio.Buffer) nativeBuffer).flip();
// Tell STB to decode the image from raw memory instead of a disk path // Tell STB to decode the image from raw memory instead of a disk path
image = stbi_load_from_memory(nativeBuffer, widthBuffer, heightBuffer, channelsBuffer, 0); image = stbi_load_from_memory(nativeBuffer, widthBuffer, heightBuffer, channelsBuffer, 0);
+31 -18
View File
@@ -5,6 +5,7 @@ import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.json.*; import org.json.*;
@@ -13,24 +14,6 @@ import org.joml.Vector4f;
public class Utilities { public class Utilities {
public static Map<Character, Integer> mainFontMap = new HashMap<>(); public static Map<Character, Integer> mainFontMap = new HashMap<>();
public static Map<Character, Integer> smallFontMap = new HashMap<>(); public static Map<Character, Integer> smallFontMap = new HashMap<>();
public static String[] testFlavor = {"outlook","travelForecast", "localForecast", "outlook"};
public static String[] flavorA = {"currentConditions","localForecast","hourlyObservations"};
public static String[] flavorB = {"hourlyObservations", "almanac", "extendedForecast", "regionalConditions"};
public static String[] flavorC = {"regionalConditions", "localForecast", "currentConditions"};
public static String[] flavorD = {"hourlyObservations", "almanac", "localForecast", "regionalConditions"};
public static String[] flavorE = {"localForecast", "extendedForecast","hourlyObservations"};
public static String[] flavorF = {"currentConditions", "regionalConditions", "localForecast", "almanac"};
public static String[] flavorG = {"localForecast"};
public static String[] flavorH = {"localForecast", "regionalforecast", "almanac", "hourlyObservations"};
public static String[] flavorI = {"currentConditions", "hourlyObservations", "regionalConditions"};
public static String[] flavorJ = {"currentConditions", "hourlyObservations", "regionalConditions", "localForecast", "almanac", "regionalForecast", "travelForecast", "extendedForecast", "outlook"};
public static String[] flavorK = {"currentConditions", "almanac", "regionalForecast", "localForecast", "extendedForecast", "hourlyObservations"};
public static String[] flavorL = {"currentConditions", "hourlyObservations", "regionalConditions", "regionalForecast", "almanac", "localForecast", "extendedForecast"};
public static String[] flavorM = {"currentConditions", "localForecast", "extendedForecast", "travelForecast"};
public static String[] flavorN = {"currentConditions", "hourlyObservations", "regionalConditions", "localForecast", "almanac", "regionalForecast", "travelForecast", "extendedForecast", "outlook", "currentConditions", "localForecast", "extendedForecast", "travelForecast"};
public static String[] flavorO = {"currentConditions", "hourlyObservations", "regionalConditions", "localForecast", "almanac", "regionalForecast", "travelForecast", "extendedForecast", "outlook", "currentConditions", "hourlyObservations", "regionalConditions", "localForecast", "almanac", "regionalForecast", "travelForecast", "extendedForecast", "outlook"};
public static String[] flavorP = {"localForecast", "extendedForecast", "currentConditions"};
public static String[] flavorQ = {"currentConditions", "almanac", "localForecast", "regionalConditions"};
static { static {
mainFontMap.put(' ', 0); mainFontMap.put(' ', 0);
@@ -400,4 +383,34 @@ public class Utilities {
public void printThirtyTwoLine() { public void printThirtyTwoLine() {
System.out.println("--------------------------------"); System.out.println("--------------------------------");
} }
public ArrayList<String> loadSegments(String flavor) throws IOException {
String json = readJsonFromResource("/resources/json/SlidesManager.json");
JSONObject jsonObject = new JSONObject(json);
JSONArray fl = jsonObject.getJSONArray(flavor);
ArrayList<String> segments = new ArrayList<>();
for (int i = 0; i < fl.length(); i++) {
segments.add(fl.getJSONObject(i).getString("segment"));
}
return segments;
}
public ArrayList<Float> loadDurations(String flavor) throws IOException {
String json = readJsonFromResource("/resources/json/SlidesManager.json");
JSONObject jsonObject = new JSONObject(json);
JSONArray fl = jsonObject.getJSONArray(flavor);
ArrayList<Float> segments = new ArrayList<>();
for (int i = 0; i < fl.length(); i++) {
segments.add(fl.getJSONObject(i).getFloat("duration"));
}
return segments;
}
} }
@@ -37,6 +37,8 @@
"Flash Flood Warning": { "headline": false, "scroll": true, "severity": "Warning" }, "Flash Flood Warning": { "headline": false, "scroll": true, "severity": "Warning" },
"Excessive Heat Watch": { "headline": true, "scroll": true, "severity": "Advisory" }, "Excessive Heat Watch": { "headline": true, "scroll": true, "severity": "Advisory" },
"Excessive Heat Warning": { "headline": true, "scroll": true, "severity": "Warning" }, "Excessive Heat Warning": { "headline": true, "scroll": true, "severity": "Warning" },
"Extreme Heat Watch": { "headline": true, "scroll": true, "severity": "Advisory" },
"Extreme Heat Warning": { "headline": true, "scroll": true, "severity": "Warning" },
"Heat Advisory": { "headline": true, "scroll": true, "severity": "Advisory" }, "Heat Advisory": { "headline": true, "scroll": true, "severity": "Advisory" },
"Tropical Storm Watch": { "headline": true, "scroll": true, "severity": "Advisory" }, "Tropical Storm Watch": { "headline": true, "scroll": true, "severity": "Advisory" },
"Tropical Storm Warning": { "headline": true, "scroll": true, "severity": "Warning" }, "Tropical Storm Warning": { "headline": true, "scroll": true, "severity": "Warning" },
+129
View File
@@ -0,0 +1,129 @@
{
"A": [
{"segment":"currentConditions", "duration": 600.0},
{"segment":"localForecast", "duration": 600.0},
{"segment":"hourlyObservations", "duration": 600.0}
],
"B": [
{"segment":"hourlyObservations", "duration": 600.0},
{"segment":"almanac", "duration": 600.0},
{"segment":"extendedForecast", "duration": 1200.0},
{"segment":"regionalConditions", "duration": 600.0}
],
"C": [
{"segment":"regionalConditions", "duration": 600.0},
{"segment":"localForecast", "duration": 600.0},
{"segment":"regionalForecast", "duration": 600.0}
],
"D": [
{"segment":"hourlyObservations", "duration": 600.0},
{"segment":"almanac", "duration": 600.0},
{"segment":"localForecast", "duration": 600.0},
{"segment":"regionalConditions", "duration": 600.0}
],
"E": [
{"segment":"localForecast", "duration": 600.0},
{"segment":"extendedForecast", "duration": 1200.0},
{"segment":"hourlyObservations", "duration": 600.0}
],
"F": [
{"segment":"currentConditions", "duration": 600.0},
{"segment":"regionalConditions", "duration": 600.0},
{"segment":"localForecast", "duration": 600.0},
{"segment":"almanac", "duration": 600.0}
],
"G": [
{"segment":"localForecast", "duration": 600.0}
],
"H": [
{"segment":"localForecast", "duration": 600.0},
{"segment":"regionalForecast", "duration": 600.0},
{"segment":"almanac", "duration": 600.0},
{"segment":"hourlyObservations", "duration": 600.0}
],
"I": [
{"segment":"currentConditions", "duration": 600.0},
{"segment":"hourlyObservations", "duration": 600.0},
{"segment":"regionalConditions", "duration": 600.0}
],
"J": [
{"segment":"currentConditions", "duration": 720.0},
{"segment":"hourlyObservations", "duration": 720.0},
{"segment":"regionalConditions", "duration": 720.0},
{"segment":"localForecast", "duration": 720.0},
{"segment":"almanac", "duration": 720.0},
{"segment":"regionalForecast", "duration": 720.0},
{"segment":"travelForecast", "duration": 2880.0},
{"segment":"extendedForecast", "duration": 1440.0},
{"segment":"outlook", "duration": 720.0}
],
"K": [
{"segment":"currentConditions", "duration": 600.0},
{"segment":"almanac", "duration": 600.0},
{"segment":"regionalForecast", "duration": 600.0},
{"segment":"localForecast", "duration": 600.0},
{"segment":"extendedForecast", "duration": 1200.0},
{"segment":"hourlyObservations", "duration": 600.0}
],
"L": [
{"segment":"currentConditions", "duration": 720.0},
{"segment":"hourlyObservations", "duration": 720.0},
{"segment":"regionalConditions", "duration": 720.0},
{"segment":"regionalForecast", "duration": 720.0},
{"segment":"almanac", "duration": 720.0},
{"segment":"localForecast", "duration": 720.0},
{"segment":"extendedForecast", "duration": 1440.0}
],
"M": [
{"segment":"currentConditions", "duration": 720.0},
{"segment":"localForecast", "duration": 720.0},
{"segment":"extendedForecast", "duration": 1440.0},
{"segment":"travelForecast", "duration": 2880.0}
],
"N": [
{"segment":"currentConditions", "duration": 720.0},
{"segment":"hourlyObservations", "duration": 720.0},
{"segment":"regionalConditions", "duration": 720.0},
{"segment":"localForecast", "duration": 720.0},
{"segment":"almanac", "duration": 720.0},
{"segment":"regionalForecast", "duration": 720.0},
{"segment":"travelForecast", "duration": 2880.0},
{"segment":"extendedForecast", "duration": 1440.0},
{"segment":"outlook", "duration": 720.0},
{"segment":"currentConditions", "duration": 720.0},
{"segment":"localForecast", "duration": 720.0},
{"segment":"extendedForecast", "duration": 1440.0},
{"segment":"travelForecast", "duration": 2880.0}
],
"O": [
{"segment":"currentConditions", "duration": 720.0},
{"segment":"hourlyObservations", "duration": 720.0},
{"segment":"regionalConditions", "duration": 720.0},
{"segment":"localForecast", "duration": 720.0},
{"segment":"almanac", "duration": 720.0},
{"segment":"regionalForecast", "duration": 720.0},
{"segment":"travelForecast", "duration": 2880.0},
{"segment":"extendedForecast", "duration": 1440.0},
{"segment":"outlook", "duration": 720.0},
{"segment":"currentConditions", "duration": 720.0},
{"segment":"hourlyObservations", "duration": 720.0},
{"segment":"regionalConditions", "duration": 720.0},
{"segment":"localForecast", "duration": 720.0},
{"segment":"almanac", "duration": 720.0},
{"segment":"regionalForecast", "duration": 720.0},
{"segment":"travelForecast", "duration": 2880.0},
{"segment":"extendedForecast", "duration": 1440.0},
{"segment":"outlook", "duration": 720.0}
],
"P": [
{"segment":"localForecast", "duration": 600.0},
{"segment":"extendedForecast", "duration": 1200.0},
{"segment":"currentConditions", "duration": 600.0}
],
"Q": [
{"segment":"currentConditions", "duration": 600.0},
{"segment":"almanac", "duration": 600.0},
{"segment":"localForecast", "duration": 600.0},
{"segment":"regionalConditions", "duration": 600.0}
]
}