mirror of
https://github.com/MistWeatherMedia/WeatherSTAR-3000-Java.git
synced 2026-11-28 14:38:08 -08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c23c4f827 | ||
|
|
27a70dc6f0 | ||
|
|
cc87e32278 | ||
|
|
5923ef2043 | ||
|
|
5801b8ab41 | ||
|
|
76c51648f3 | ||
|
|
a3e5e81500 | ||
|
|
a2791ddd91 | ||
|
|
dbe9b0964d | ||
|
|
742714fbac | ||
|
|
a29f4d0829 | ||
|
|
02e0a7cf1f | ||
|
|
5177d0fead | ||
|
|
1cc60fe38c | ||
|
|
ea86c54d5a | ||
|
|
35357d3082 | ||
|
|
a4f69d5b1b | ||
|
|
5cdc6af9dd |
No files matched your search
@@ -1,7 +1,7 @@
|
||||
# WeatherSTAR 3000 Simulator
|
||||
WeatherSTAR 3000 Simulator in Java by Joe Molinelli/Mist Weather Media
|
||||
|
||||
Compatible with Java 25+
|
||||
Compatible with Java 8+
|
||||
|
||||
------------
|
||||

|
||||
@@ -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!
|
||||
|
||||
Either of the following methods can be used:
|
||||
|
||||
## Installation Instructions (JAR):
|
||||
## Installation Instructions:
|
||||
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
|
||||
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.
|
||||
|
||||
Many thanks for using our simulator! We hope you like it.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>WS3000</groupId>
|
||||
<artifactId>weatherstar3000</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.8.0</version>
|
||||
|
||||
<name>weatherstar3000</name>
|
||||
<url>https://github.com/MistWeatherMedia/WeatherSTAR-3000-Java</url>
|
||||
@@ -186,25 +186,15 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>2.0.13</version>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.10.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.5.6</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>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20231013</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javazoom</groupId>
|
||||
@@ -586,6 +576,19 @@
|
||||
<artifactId>joml</artifactId>
|
||||
<version>${joml.version}</version>
|
||||
</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>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -4,15 +4,17 @@ import org.json.JSONObject;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Almanac extends Thread {
|
||||
Utilities utl = new Utilities();
|
||||
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
String today;
|
||||
String tomorrow;
|
||||
String todaySunrise;
|
||||
@@ -24,55 +26,59 @@ public class Almanac extends Thread {
|
||||
String tomorrowHigh;
|
||||
String tomorrowLow;
|
||||
String normalPrecip;
|
||||
|
||||
String getDay(String icaoCode, String key, int dayNum) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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()
|
||||
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 {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
String day = JSONResponse.getJSONArray("dayOfWeek").getString(dayNum);
|
||||
|
||||
String responseBody = response.body().string();
|
||||
JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
String day = jsonResponse.getJSONArray("dayOfWeek").getString(dayNum);
|
||||
|
||||
String[] dayNames = {" SUNDAY ", " MONDAY ", " TUESDAY ", "WEDNESDAY", "THURSDAY ", " FRIDAY ", "SATURDAY "};
|
||||
return switch (day) {
|
||||
case "Sunday" -> dayNames[0];
|
||||
case "Monday" -> dayNames[1];
|
||||
case "Tuesday" -> dayNames[2];
|
||||
case "Wednesday" -> dayNames[3];
|
||||
case "Thursday" -> dayNames[4];
|
||||
case "Friday" -> dayNames[5];
|
||||
case "Saturday" -> dayNames[6];
|
||||
default -> " ";
|
||||
};
|
||||
switch (day) {
|
||||
case "Sunday": return dayNames[0];
|
||||
case "Monday": return dayNames[1];
|
||||
case "Tuesday": return dayNames[2];
|
||||
case "Wednesday": return dayNames[3];
|
||||
case "Thursday": return dayNames[4];
|
||||
case "Friday": return dayNames[5];
|
||||
case "Saturday": return dayNames[6];
|
||||
default: return " ";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
|
||||
String getSunrise(String icaoCode, String key, int dayNum) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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()
|
||||
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 {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
String time = JSONResponse.getJSONArray("sunriseTimeLocal").getString(dayNum);
|
||||
|
||||
String responseBody = response.body().string();
|
||||
JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
String time = jsonResponse.getJSONArray("sunriseTimeLocal").getString(dayNum);
|
||||
|
||||
int hour = Integer.parseInt(time.substring(11, 13));
|
||||
int dispHour = hour > 12 ? hour - 12 : hour;
|
||||
@@ -85,22 +91,24 @@ public class Almanac extends Thread {
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
|
||||
String getSunset(String icaoCode, String key, int dayNum) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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()
|
||||
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 {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
String time = JSONResponse.getJSONArray("sunsetTimeLocal").getString(dayNum);
|
||||
|
||||
String responseBody = response.body().string();
|
||||
JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
String time = jsonResponse.getJSONArray("sunsetTimeLocal").getString(dayNum);
|
||||
|
||||
int hour = Integer.parseInt(time.substring(11, 13));
|
||||
int dispHour = hour > 12 ? hour - 12 : hour;
|
||||
@@ -113,67 +121,77 @@ public class Almanac extends Thread {
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
|
||||
String getMonth(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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()
|
||||
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 {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
return "error";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
return JSONResponse.getJSONArray("validTimeLocal").getString(0).substring(5, 7);
|
||||
|
||||
String responseBody = response.body().string();
|
||||
JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
|
||||
return jsonResponse.getJSONArray("validTimeLocal").getString(0).substring(5, 7);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
String getDayDate(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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()
|
||||
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 {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
return "error";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
return JSONResponse.getJSONArray("validTimeLocal").getString(0).substring(8, 10);
|
||||
|
||||
String responseBody = response.body().string();
|
||||
JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
|
||||
return jsonResponse.getJSONArray("validTimeLocal").getString(0).substring(8, 10);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
String getTempMax(String icaoCode, String key, int dayNum, String month, String day) {
|
||||
if (Objects.equals(month, "error") || Objects.equals(day, "error")) {
|
||||
return " ";
|
||||
}
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.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()
|
||||
|
||||
String url = "https://api.weather.com/v3/wx/almanac/daily/5day?icaoCode=" + icaoCode + "&format=json&units=e&startDay=" + day + "&startMonth=" + month + "&apiKey=" + key;
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.get()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
int temp = JSONResponse.getJSONArray("temperatureAverageMax").getInt(dayNum);
|
||||
|
||||
String responseBody = response.body().string();
|
||||
JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
|
||||
int temp = jsonResponse.getJSONArray("temperatureAverageMax").getInt(dayNum);
|
||||
|
||||
return utl.rjust(temp + " \\F", 6, " ");
|
||||
} catch (Exception e) {
|
||||
@@ -181,25 +199,29 @@ public class Almanac extends Thread {
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
|
||||
String getTempMin(String icaoCode, String key, int dayNum, String month, String day) {
|
||||
if (Objects.equals(month, "error") || Objects.equals(day, "error")) {
|
||||
return " ";
|
||||
}
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.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()
|
||||
|
||||
String url = "https://api.weather.com/v3/wx/almanac/daily/5day?icaoCode=" + icaoCode + "&format=json&units=e&startDay=" + day + "&startMonth=" + month + "&apiKey=" + key;
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.get()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
int temp = JSONResponse.getJSONArray("temperatureAverageMin").getInt(dayNum);
|
||||
|
||||
String responseBody = response.body().string();
|
||||
JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
|
||||
int temp = jsonResponse.getJSONArray("temperatureAverageMin").getInt(dayNum);
|
||||
|
||||
return utl.rjust(temp + " \\F", 6, " ");
|
||||
} catch (Exception e) {
|
||||
@@ -207,41 +229,48 @@ public class Almanac extends Thread {
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
|
||||
String getPrecip(String icaoCode, String key, String month, String day) {
|
||||
if (Objects.equals(month, "error") || Objects.equals(day, "error")) {
|
||||
return " ";
|
||||
return utl.ljust("", 32, " ");
|
||||
}
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.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()
|
||||
|
||||
String url = "https://api.weather.com/v3/wx/almanac/daily/5day?icaoCode=" + icaoCode + "&format=json&units=e&startDay=" + day + "&startMonth=" + month + "&apiKey=" + key;
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.get()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
return utl.ljust("", 32, " ");
|
||||
}
|
||||
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 cmonth = utl.ljust("NORMAL " + monthNames[Integer.parseInt(month)] + " PRECIP", 23, " ");
|
||||
String responseBody = response.body().string();
|
||||
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, " ") + " ";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
return utl.ljust("", 32, " ");
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
String mainIcao = Main.mainIcao;
|
||||
String key = Main.key;
|
||||
String todayMonth = Main.todayMonth;
|
||||
String todayDay = Main.todayDay;
|
||||
String todayMonth = getMonth(mainIcao, key);;
|
||||
String todayDay = getDayDate(mainIcao, key);;
|
||||
Main.almanac.today = getDay(mainIcao, key, 0);
|
||||
Main.almanac.tomorrow = getDay(mainIcao, key, 1);
|
||||
Main.almanac.todaySunrise = getSunrise(mainIcao, key, 0);
|
||||
|
||||
@@ -1,152 +1,150 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
public class Bulletin extends Thread {
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
static Utilities utl = new Utilities();
|
||||
ArrayList<String> bulletinText = new ArrayList<>();
|
||||
//String color;
|
||||
//boolean severe;
|
||||
//boolean crawl;
|
||||
|
||||
public ArrayList<String> getBulletin(String key, String lat, String lon) {
|
||||
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());
|
||||
|
||||
for (int i = 0; i < responseObject.getJSONArray("alerts").length(); i++) {
|
||||
String headline = responseObject.getJSONArray("alerts").getJSONObject(i).getString("eventDescription");
|
||||
|
||||
String detailKey = responseObject.getJSONArray("alerts").getJSONObject(i).getString("detailKey");
|
||||
if (utl.isScroll(headline)) {
|
||||
return eachAlert(detailKey, key);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
words.clear();
|
||||
words.add("None");
|
||||
words.add("NOBULLETINCRAWL");
|
||||
|
||||
return words;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
words.clear();
|
||||
words.add("None");
|
||||
words.add("NOBULLETINCRAWL");
|
||||
return words;
|
||||
}
|
||||
}
|
||||
ArrayList<String> words = new ArrayList<>();
|
||||
|
||||
String url = "https://api.weather.com/v3/alerts/headlines?geocode=" + lat + "," + lon + "&format=json&language=en-US&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()) {
|
||||
words.add("None");
|
||||
words.add("NOBULLETINCRAWL");
|
||||
return words;
|
||||
}
|
||||
|
||||
JSONObject responseObject = new JSONObject(response.body().string());
|
||||
|
||||
for (int i = 0; i < responseObject.getJSONArray("alerts").length(); i++) {
|
||||
JSONObject alertItem = responseObject.getJSONArray("alerts").getJSONObject(i);
|
||||
String headline = alertItem.getString("eventDescription");
|
||||
String detailKey = alertItem.getString("detailKey");
|
||||
|
||||
if (utl.isScroll(headline)) {
|
||||
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) {
|
||||
ArrayList<String> words = new ArrayList<>();
|
||||
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.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());
|
||||
|
||||
String headline = ResponseObj.getJSONObject("alertDetail").getString("eventDescription");
|
||||
|
||||
String alert = ResponseObj.getJSONObject("alertDetail").getJSONArray("texts").getJSONObject(0).getString("description").toUpperCase();
|
||||
|
||||
words.clear();
|
||||
|
||||
words.addAll(Arrays.asList(alert.replace("\n\n", " *newline* ").split("\\s+")));
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
ArrayList<String> finalWords = new ArrayList<>();
|
||||
|
||||
finalWords.add(headline);
|
||||
|
||||
for (int i = 0; i <= words.size()-1; i++) {
|
||||
if (words.get(i).equals("*newline*")) {
|
||||
if (!sb.isEmpty()) {
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
}
|
||||
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
int wordlength = words.get(i).length();
|
||||
if (wordlength > 32) {
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
|
||||
if (!sb.isEmpty()) {sb.append(" ");}
|
||||
sb.append(words.get(i));
|
||||
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
} else {
|
||||
if (wordlength + sb.length() + 1 <= 32) {
|
||||
if (!sb.isEmpty()) {sb.append(" ");}
|
||||
sb.append(words.get(i));
|
||||
} else {
|
||||
i--;
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
|
||||
return finalWords;
|
||||
} catch (Exception e) {
|
||||
words.clear();
|
||||
words.add("None");
|
||||
words.add("NOBULLETINCRAWL");
|
||||
return words;
|
||||
}
|
||||
ArrayList<String> words = new ArrayList<>();
|
||||
|
||||
String url = "https://api.weather.com/v3/alerts/detail?alertId=" + detailKey
|
||||
+ "&format=json&language=en-US&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()) {
|
||||
words.add("None");
|
||||
words.add("NOBULLETINCRAWL");
|
||||
return words;
|
||||
}
|
||||
|
||||
JSONObject responseObj = new JSONObject(response.body().string());
|
||||
JSONObject alertDetail = responseObj.getJSONObject("alertDetail");
|
||||
|
||||
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+")));
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
ArrayList<String> finalWords = new ArrayList<>();
|
||||
|
||||
finalWords.add(headline);
|
||||
|
||||
for (int i = 0; i <= words.size() - 1; i++) {
|
||||
if (words.get(i).equals("*newline*")) {
|
||||
if (!(sb.length() == 0)) {
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
}
|
||||
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
int wordlength = words.get(i).length();
|
||||
if (wordlength > 32) {
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
|
||||
if (!(sb.length() == 0)) { sb.append(" "); }
|
||||
sb.append(words.get(i));
|
||||
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
} else {
|
||||
if (wordlength + sb.length() + 1 <= 32) {
|
||||
if (!(sb.length() == 0)) { sb.append(" "); }
|
||||
sb.append(words.get(i));
|
||||
} else {
|
||||
i--;
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
finalWords.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
|
||||
return finalWords;
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
words.clear();
|
||||
words.add("None");
|
||||
words.add("NOBULLETINCRAWL");
|
||||
return words;
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
String key = Main.key;
|
||||
String mainLat = Main.mainLat;
|
||||
String mainLon = Main.mainLon;
|
||||
Main.bulletin.bulletinText.clear();
|
||||
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 java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
//import java.text.DecimalFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.Month;
|
||||
|
||||
public class CurrentConditions extends Thread {
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
String locName;
|
||||
String condition;
|
||||
String temperature;
|
||||
@@ -25,46 +26,53 @@ public class CurrentConditions extends Thread {
|
||||
String visibility;
|
||||
String ceiling;
|
||||
String precip;
|
||||
static Utilities utl = new Utilities();
|
||||
|
||||
Utilities utl = new Utilities();
|
||||
|
||||
static String getLocName(String displayName) {return "CONDITIONS AT " + utl.ljust(displayName.toUpperCase(), 14, " ").substring(0, 14);}
|
||||
static String getCondition(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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))
|
||||
.GET()
|
||||
String getLocName(String displayName) {return "CONDITIONS AT " + utl.ljust(displayName.toUpperCase(), 14, " ").substring(0, 14);}
|
||||
|
||||
String getCondition(String icaoCode, String key) {
|
||||
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")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return "NO REPORT";
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
return "NO CURRENT REPORT";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
String responseBody = response.body().string();
|
||||
JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
|
||||
return JSONResponse.getString("wxPhraseLong").toUpperCase();
|
||||
return jsonResponse.getString("wxPhraseLong").toUpperCase();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "NO REPORT";
|
||||
return "NO CURRENT REPORT";
|
||||
}
|
||||
}
|
||||
static String getTemperature(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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))
|
||||
.GET()
|
||||
|
||||
String getTemperature(String icaoCode, String key) {
|
||||
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")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
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";
|
||||
} catch (Exception e) {
|
||||
@@ -72,23 +80,27 @@ public class CurrentConditions extends Thread {
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
static String getFeelsLike(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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))
|
||||
.GET()
|
||||
|
||||
String getFeelsLike(String icaoCode, String key) {
|
||||
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")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
int feelTemp = JSONResponse.getInt("temperatureFeelsLike");
|
||||
int temp = JSONResponse.getInt("temperature");
|
||||
String responseBody = response.body().string();
|
||||
JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
|
||||
int feelTemp = jsonResponse.getInt("temperatureFeelsLike");
|
||||
int temp = jsonResponse.getInt("temperature");
|
||||
|
||||
if (temp == feelTemp) {
|
||||
return " ";
|
||||
} else {
|
||||
@@ -98,28 +110,31 @@ public class CurrentConditions extends Thread {
|
||||
return "WIND CHILL:" + utl.rjust(Integer.toString(feelTemp), 3, " ") + "\\F";
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
static String getHumidity(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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))
|
||||
.GET()
|
||||
|
||||
String getHumidity(String icaoCode, String key) {
|
||||
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")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
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 + "%";
|
||||
} catch (Exception e) {
|
||||
@@ -127,22 +142,26 @@ public class CurrentConditions extends Thread {
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
static String getDewPoint(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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))
|
||||
.GET()
|
||||
|
||||
String getDewPoint(String icaoCode, String key) {
|
||||
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")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
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";
|
||||
} catch (Exception e) {
|
||||
@@ -150,26 +169,29 @@ public class CurrentConditions extends Thread {
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
static String getPressure(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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))
|
||||
.GET()
|
||||
|
||||
String getPressure(String icaoCode, String key) {
|
||||
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")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
//DecimalFormat df = new DecimalFormat("#.##");
|
||||
float pres = JSONResponse.getFloat("pressureAltimeter");
|
||||
String responseBody = response.body().string();
|
||||
JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
|
||||
float pres = jsonResponse.getFloat("pressureAltimeter");
|
||||
String fpres = String.format("%.2f", pres);
|
||||
|
||||
int presCode = JSONResponse.getInt("pressureTendencyCode");
|
||||
int presCode = jsonResponse.getInt("pressureTendencyCode");
|
||||
String fpresCode = "";
|
||||
if (presCode == 0) {
|
||||
fpresCode = "IN.";
|
||||
@@ -185,51 +207,60 @@ public class CurrentConditions extends Thread {
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
static String getWind(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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))
|
||||
.GET()
|
||||
|
||||
String getWind(String icaoCode, String key) {
|
||||
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")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
int windDir = JSONResponse.getInt("windDirection");
|
||||
int windSpeed = JSONResponse.getInt("windSpeed");
|
||||
String responseBody = response.body().string();
|
||||
JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
|
||||
int windDir = jsonResponse.getInt("windDirection");
|
||||
int windSpeed = jsonResponse.getInt("windSpeed");
|
||||
|
||||
if (windSpeed == 0) {
|
||||
return "WIND: CALM ";
|
||||
} 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) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
static String getGusts(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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))
|
||||
.GET()
|
||||
|
||||
String getGusts(String icaoCode, String key) {
|
||||
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")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
String gus;
|
||||
gus = JSONResponse.isNull("windGust") ? " " : "GUSTS TO " + utl.rjust(Integer.toString(JSONResponse.getInt("windGust")), 3, " ");
|
||||
String responseBody = response.body().string();
|
||||
JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
|
||||
String gus = jsonResponse.isNull("windGust")
|
||||
? " "
|
||||
: "GUSTS TO " + utl.rjust(Integer.toString(jsonResponse.getInt("windGust")), 3, " ");
|
||||
|
||||
return gus;
|
||||
} catch (Exception e) {
|
||||
@@ -237,22 +268,26 @@ public class CurrentConditions extends Thread {
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
static String getVisiblity(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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))
|
||||
.GET()
|
||||
|
||||
String getVisiblity(String icaoCode, String key) {
|
||||
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")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
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;
|
||||
} catch (Exception e) {
|
||||
@@ -260,49 +295,58 @@ public class CurrentConditions extends Thread {
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
|
||||
String getCeiling(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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))
|
||||
.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")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
|
||||
String getPrecip(String key, String lat, String lon) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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))
|
||||
.GET()
|
||||
String url = "https://api.weather.com/v1/geocode/" + lat + "/" + lon + "/observations/current.json?language=en-US&units=e&apiKey=" + key;
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.get()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
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();
|
||||
|
||||
try {
|
||||
JSONObject obsObject = JSONResponse.getJSONObject("observation");
|
||||
JSONObject obsObject = jsonResponse.getJSONObject("observation");
|
||||
JSONObject impObj = obsObject.getJSONObject("imperial");
|
||||
String fprecip = String.format("%.2f", impObj.getFloat("precip_mtd"));
|
||||
String prec = utl.rjust(fprecip + " IN", 8, " ");
|
||||
@@ -316,6 +360,7 @@ public class CurrentConditions extends Thread {
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
String mainLocName = Main.mainLocName.getText();
|
||||
String key = Main.key;
|
||||
|
||||
@@ -2,43 +2,64 @@ package WS3000.weatherstar3000;
|
||||
|
||||
public class DataRunner extends Thread {
|
||||
public void run() {
|
||||
if (Main.ztOption.equals("Location Time")) {
|
||||
Main.timeZone = Main.getTimeZone(Main.mainIcao);
|
||||
}
|
||||
//System.out.println("Data collection");
|
||||
Main.currentConditions = new CurrentConditions();
|
||||
Main.hourlyObservations = new HourlyObservations();
|
||||
Main.regionalConditions = new RegionalConditions();
|
||||
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.extendedForecast = new ExtendedForecast();
|
||||
Main.outlook = new Outlook();
|
||||
Main.travelForecast = new TravelForecast();
|
||||
Main.bulletin = new Bulletin();
|
||||
Main.tides = new Tides();
|
||||
|
||||
|
||||
Main.currentConditions.start();
|
||||
Main.hourlyObservations.start();
|
||||
Main.regionalConditions.start();
|
||||
Main.localForecast.start();
|
||||
Main.almanac.start();
|
||||
|
||||
if (Main.tidesEnabled) {
|
||||
Main.tides.start();
|
||||
} else {
|
||||
Main.almanac.start();
|
||||
}
|
||||
|
||||
Main.regionalForecast.start();
|
||||
Main.extendedForecast.start();
|
||||
Main.outlook.start();
|
||||
Main.travelForecast.start();
|
||||
Main.bulletin.start();
|
||||
Main.tides.start();
|
||||
|
||||
|
||||
try {
|
||||
Main.currentConditions.join();
|
||||
Main.hourlyObservations.join();
|
||||
Main.regionalConditions.join();
|
||||
Main.localForecast.join();
|
||||
Main.almanac.join();
|
||||
|
||||
if (Main.tidesEnabled) {
|
||||
Main.tides.join();
|
||||
} else {
|
||||
Main.almanac.join();
|
||||
}
|
||||
|
||||
Main.regionalForecast.join();
|
||||
Main.extendedForecast.join();
|
||||
Main.outlook.join();
|
||||
Main.travelForecast.join();
|
||||
Main.bulletin.join();
|
||||
Main.tides.join();
|
||||
|
||||
LoadingScreen.dataFinish = true;
|
||||
SlidesRunner.collectingData = false;
|
||||
//ystem.out.println("data finished, destroying thread");
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.json.JSONObject;
|
||||
@@ -11,6 +11,8 @@ import org.json.JSONObject;
|
||||
import util.Utilities;
|
||||
|
||||
public class ExtendedForecast extends Thread {
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
String dayOne;
|
||||
String dayTwo;
|
||||
String dayThree;
|
||||
@@ -24,109 +26,122 @@ public class ExtendedForecast extends Thread {
|
||||
String highTwo;
|
||||
String highThree;
|
||||
Utilities utl = new Utilities();
|
||||
|
||||
String getDayName(String icaoCode, String key, int day) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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;
|
||||
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();
|
||||
|
||||
return utl.ljust(new JSONObject(ResponseBody).getJSONArray("dayOfWeek").getString(day + 2).toUpperCase(), 10, " ");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
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> values = new ArrayList<>();
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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));
|
||||
values.add(utl.getForecastEx(dpData.getJSONArray("iconCodeExtend").getInt(ex + bump), 1));
|
||||
|
||||
return values;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
values.add(" ");
|
||||
values.add(" ");
|
||||
return values;
|
||||
}
|
||||
ArrayList<String> values = new ArrayList<>();
|
||||
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()) {
|
||||
values.add(" ");
|
||||
values.add(" ");
|
||||
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) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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) ? 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 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);
|
||||
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) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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) ? 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 " ";
|
||||
}
|
||||
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);
|
||||
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() {
|
||||
String key = Main.key;
|
||||
String mainIcao = Main.mainIcao;
|
||||
|
||||
@@ -4,13 +4,15 @@ import org.json.JSONObject;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class HourlyObservations extends Thread {
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
ArrayList<String> locName = new ArrayList<>();
|
||||
ArrayList<String> temperature = new ArrayList<>();
|
||||
ArrayList<String> condition = new ArrayList<>();
|
||||
@@ -18,67 +20,76 @@ public class HourlyObservations extends Thread {
|
||||
Utilities utl = new Utilities();
|
||||
|
||||
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) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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))
|
||||
.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")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
|
||||
String getCondition(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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))
|
||||
.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")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
return "NO REPORT";
|
||||
}
|
||||
}
|
||||
|
||||
String getWind(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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))
|
||||
.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")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
return " ";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
int windDir = JSONResponse.getInt("windDirection");
|
||||
int windSpeed = JSONResponse.getInt("windSpeed");
|
||||
String responseBody = response.body().string();
|
||||
JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
|
||||
int windDir = jsonResponse.getInt("windDirection");
|
||||
int windSpeed = jsonResponse.getInt("windSpeed");
|
||||
|
||||
return utl.formatWind(windSpeed, windDir, false);
|
||||
} catch (Exception e) {
|
||||
@@ -86,12 +97,17 @@ public class HourlyObservations extends Thread {
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
ArrayList<String> nearNames = new ArrayList<>();
|
||||
nearNames.addAll(Main.nearNames);
|
||||
ArrayList<String> nearIcaos = new ArrayList<>();;
|
||||
nearIcaos.addAll(Main.nearIcaos);
|
||||
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++) {
|
||||
Main.hourlyObservations.locName.add(getLocName(nearNames.get(i)));
|
||||
Main.hourlyObservations.temperature.add(getTemperature(nearIcaos.get(i), key));
|
||||
|
||||
@@ -5,14 +5,16 @@ import org.json.JSONObject;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class LocalForecast extends Thread {
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
ArrayList<String> bulletin = new ArrayList<>();
|
||||
ArrayList<String> forecastOne = 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> words = new ArrayList<>();
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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()
|
||||
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 {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
words.add("NO REPORT");
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
words.add("NO");
|
||||
words.add("REPORT");
|
||||
return words;
|
||||
}
|
||||
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;
|
||||
String fullText = dpData.getJSONArray("daypartName").getString(forecastId + bump).replaceAll("Tomorrow", JSONResponse.getJSONArray("dayOfWeek").getString(bump)).toUpperCase() +
|
||||
|
||||
String responseBody = response.body().string();
|
||||
JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
JSONObject dpData = jsonResponse.getJSONArray("daypart").getJSONObject(0);
|
||||
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();
|
||||
String[] splitwords = fullText.split("\\s+");
|
||||
@@ -48,48 +55,50 @@ public class LocalForecast extends Thread {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
words.clear();
|
||||
words.add("NO REPORT");
|
||||
words.add("NO");
|
||||
words.add("REPORT");
|
||||
return words;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ArrayList<String> getBulletin(String key, String lat, String lon) {
|
||||
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()
|
||||
String url = "https://api.weather.com/v3/alerts/headlines?geocode=" + lat + "," + lon
|
||||
+ "&format=json&language=en-US&apiKey=" + key;
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.get()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
words.add("NOBULLETIN");
|
||||
return words;
|
||||
}
|
||||
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
JSONArray alertData = JSONResponse.getJSONArray("alerts");
|
||||
String responseBody = response.body().string();
|
||||
JSONObject jsonResponse = new JSONObject(responseBody);
|
||||
JSONArray alertData = jsonResponse.getJSONArray("alerts");
|
||||
StringBuilder fullText = new StringBuilder();
|
||||
|
||||
fullText.setLength(0);
|
||||
|
||||
for (int i = 0; i < alertData.length(); i++) {
|
||||
if (utl.isHeadline(alertData.getJSONObject(i).getString("eventDescription"))) {
|
||||
if (!fullText.isEmpty()) {fullText.append(" *NEWLINE* ");}
|
||||
fullText.append(alertData.getJSONObject(i).getString("headlineText").toUpperCase());
|
||||
}
|
||||
if (utl.isHeadline(alertData.getJSONObject(i).getString("eventDescription"))) {
|
||||
if (!(fullText.length() == 0)) {
|
||||
fullText.append(" *NEWLINE* ");
|
||||
}
|
||||
fullText.append(alertData.getJSONObject(i).getString("headlineText").toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
words.clear();
|
||||
|
||||
if (!fullText.isEmpty()) {
|
||||
String[] splitwords = fullText.toString().split("\\s+");
|
||||
|
||||
words.addAll(Arrays.asList(splitwords));
|
||||
if (!(fullText.length() == 0)) {
|
||||
String[] splitwords = fullText.toString().split("\\s+");
|
||||
words.addAll(Arrays.asList(splitwords));
|
||||
} else {
|
||||
words.add("NOBULLETIN");
|
||||
words.add("NOBULLETIN");
|
||||
}
|
||||
|
||||
return words;
|
||||
@@ -100,6 +109,7 @@ public class LocalForecast extends Thread {
|
||||
return words;
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
String mainIcao = Main.mainIcao;
|
||||
String key = Main.key;
|
||||
|
||||
@@ -18,16 +18,19 @@ import java.io.FileWriter;
|
||||
import java.util.Scanner;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class Main {
|
||||
static String selectedFlavor;
|
||||
@@ -41,8 +44,6 @@ public class Main {
|
||||
static String mainIcao;
|
||||
static String mainLon;
|
||||
static String mainLat;
|
||||
static String todayMonth;
|
||||
static String todayDay;
|
||||
static int simWidth;
|
||||
static int simHeight;
|
||||
static boolean fullscreen = false;
|
||||
@@ -60,6 +61,9 @@ public class Main {
|
||||
static Bulletin bulletin;
|
||||
static Tides tides;
|
||||
|
||||
static String ztOption;
|
||||
static ZoneId timeZone;
|
||||
|
||||
static JFrame settingsWindow;
|
||||
|
||||
static ArrayList<String> nearNames = new ArrayList<>();
|
||||
@@ -94,10 +98,9 @@ public class Main {
|
||||
}
|
||||
*/
|
||||
//things to add:
|
||||
//airport conditions
|
||||
//air quality
|
||||
//tides
|
||||
System.out.println("WeatherSTAR 3000 Simulator Version 1.5.0");
|
||||
//optimized LookAndFeels?
|
||||
//multiple ad crawls (up to 7)
|
||||
System.out.println("WeatherSTAR 3000 Simulator Version 1.8.0");//remember joe, 1.8 for java 8 and 17 for the other, JAVA 8
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
if (userDir != null && !userDir.isEmpty()) {
|
||||
@@ -382,7 +385,7 @@ public class Main {
|
||||
|
||||
//tides
|
||||
JPanel tPanel = new JPanel(new GridLayout(0, 1, 0, 0));
|
||||
tPanel.setBorder(BorderFactory.createTitledBorder("Tides Locations"));
|
||||
tPanel.setBorder(BorderFactory.createTitledBorder("Tides Locations (OPTIONAL)"));
|
||||
|
||||
JPanel t1Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
t1Panel.add(new JLabel("Station ID"));
|
||||
@@ -447,6 +450,12 @@ public class Main {
|
||||
ldlDropdown.setSelectedIndex(0);
|
||||
r2Panel.add(ldlDropdown);
|
||||
|
||||
r2Panel.add(new JLabel("Time Zone"));
|
||||
String[] timeZoneOptions = {"Location Time", "System Time", "US/Eastern", "US/Central", "US/Mountain", "US/Arizona", "US/Pacific", "US/Alaska", "US/Aleutian", "US/Hawaii", "US/Samoa"};
|
||||
JComboBox timeZoneDropdown = new JComboBox(timeZoneOptions);
|
||||
timeZoneDropdown.setSelectedIndex(0);
|
||||
r2Panel.add(timeZoneDropdown);
|
||||
|
||||
rPanel.add(r2Panel);
|
||||
|
||||
JPanel r3Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
@@ -871,6 +880,16 @@ public class Main {
|
||||
break;
|
||||
}
|
||||
|
||||
ztOption = timeZoneDropdown.getSelectedItem().toString();
|
||||
|
||||
if (ztOption.equals("Location Time")) {
|
||||
timeZone = getTimeZone(mainIcao);
|
||||
} else if (ztOption.equals("System Time")) {
|
||||
timeZone = ZoneId.systemDefault();
|
||||
} else {
|
||||
timeZone = ZoneId.of(timeZoneDropdown.getSelectedItem().toString());
|
||||
}
|
||||
|
||||
selectedFlavor = (String) flavorDropdown.getSelectedItem();
|
||||
|
||||
simWidth = Integer.parseInt(widthField.getText());
|
||||
@@ -879,10 +898,6 @@ public class Main {
|
||||
mainLat = icaoToLat(mainIcao, key);
|
||||
mainLon = icaoToLon(mainIcao, key);
|
||||
|
||||
almanac = new Almanac();
|
||||
todayMonth = almanac.getMonth(mainIcao, key);
|
||||
todayDay = almanac.getDayDate(mainIcao, key);
|
||||
|
||||
wr.start();
|
||||
|
||||
settingsErrorThrown = false;
|
||||
@@ -893,42 +908,53 @@ public class Main {
|
||||
|
||||
settingsWindow.setVisible(true);
|
||||
}
|
||||
|
||||
static String checkIcaoCode(String code, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/location/point?icaoCode=" + code
|
||||
+ "&language=en-US&format=json&apiKey=" + key))
|
||||
.GET() // Or .POST(HttpRequest.BodyPublishers.ofString("your_json_body"))
|
||||
.header("Accept", "application/json").build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
if (Response.statusCode() == 401) {
|
||||
return "API Key error";
|
||||
} else {
|
||||
return "Invalid ICAO Code";
|
||||
}
|
||||
|
||||
static ZoneId getTimeZone(String icaoCode) {
|
||||
final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
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 ZoneId.systemDefault();
|
||||
}
|
||||
|
||||
return "noerror";
|
||||
|
||||
String responseBody = response.body().string();
|
||||
|
||||
JSONObject JSONResponse = new JSONObject(responseBody);
|
||||
String time = JSONResponse.getJSONArray("validTimeLocal").getString(0);
|
||||
|
||||
return ZonedDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ")).getZone();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "Server Error";
|
||||
return ZoneId.systemDefault();
|
||||
}
|
||||
}
|
||||
|
||||
static String icaoToLat(String code, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/location/point?icaoCode=" + code
|
||||
+ "&language=en-US&format=json&apiKey=" + key))
|
||||
.GET() // Or .POST(HttpRequest.BodyPublishers.ofString("your_json_body"))
|
||||
.header("Accept", "application/json").build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
String url = "https://api.weather.com/v3/location/point?icaoCode=" + code + "&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 "Server Error";
|
||||
}
|
||||
|
||||
String responseBody = response.body().string();
|
||||
|
||||
JSONObject JSONResponse = new JSONObject(responseBody);
|
||||
JSONObject locationObject = JSONResponse.getJSONObject("location");
|
||||
|
||||
return Float.toString(locationObject.getFloat("latitude"));
|
||||
@@ -939,16 +965,24 @@ public class Main {
|
||||
}
|
||||
|
||||
static String icaoToLon(String code, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/location/point?icaoCode=" + code
|
||||
+ "&language=en-US&format=json&apiKey=" + key))
|
||||
.GET() // Or .POST(HttpRequest.BodyPublishers.ofString("your_json_body"))
|
||||
.header("Accept", "application/json").build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
String url = "https://api.weather.com/v3/location/point?icaoCode=" + code + "&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 "Server Error";
|
||||
}
|
||||
|
||||
String responseBody = response.body().string();
|
||||
|
||||
JSONObject JSONResponse = new JSONObject(responseBody);
|
||||
JSONObject locationObject = JSONResponse.getJSONObject("location");
|
||||
|
||||
return Float.toString(locationObject.getFloat("longitude"));
|
||||
|
||||
@@ -1,35 +1,239 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
//import java.net.URI;
|
||||
//import java.net.http.HttpClient;
|
||||
//import java.net.http.HttpRequest;
|
||||
//import java.net.http.HttpResponse;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.ArrayList;
|
||||
import org.locationtech.jts.geom.Coordinate;
|
||||
import org.locationtech.jts.geom.GeometryFactory;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.locationtech.jts.geom.Polygon;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
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 org.json.JSONObject;
|
||||
|
||||
public class Outlook extends Thread {
|
||||
static Utilities utl = new Utilities();
|
||||
String month;
|
||||
ArrayList<String> outlook = new ArrayList<>();
|
||||
String getMonth() {
|
||||
LocalDate cdate = LocalDate.now();
|
||||
Month cmonth = cdate.getMonth();
|
||||
|
||||
return cmonth.name().toUpperCase();
|
||||
}
|
||||
ArrayList<String> getOutlook() {
|
||||
ArrayList<String> outlook = new ArrayList<>();
|
||||
outlook.add("NO");
|
||||
outlook.add("REPORT");
|
||||
return outlook;
|
||||
String precipitation;
|
||||
String temperature;
|
||||
|
||||
private static final GeometryFactory geometryFactory = new GeometryFactory();
|
||||
|
||||
String getOutlook(String type, String lat, String lon) {//type prcp or temp
|
||||
try {
|
||||
String zipFile = "https://ftp.cpc.ncep.noaa.gov/GIS/us_tempprcpfcst/monthlyupdate/monthupd_" + type + "_latest.zip";
|
||||
|
||||
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() {
|
||||
Main.outlook.month = getMonth();
|
||||
Main.outlook.outlook = getOutlook();
|
||||
String mainLat = Main.mainLat;
|
||||
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 java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RegionalConditions extends Thread {
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
ArrayList<String> locName = new ArrayList<>();
|
||||
ArrayList<String> temperature = new ArrayList<>();
|
||||
ArrayList<String> condition = new ArrayList<>();
|
||||
Utilities utl = new Utilities();
|
||||
|
||||
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) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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))
|
||||
.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")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
return "NO REPORT";
|
||||
}
|
||||
}
|
||||
|
||||
String getTemperature(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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))
|
||||
.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")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
ArrayList<String> regConNames = new ArrayList<>();
|
||||
regConNames.addAll(Main.regConNames);
|
||||
ArrayList<String> regConIcaos = new ArrayList<>();
|
||||
regConIcaos.addAll(Main.regConIcaos);
|
||||
String key = Main.key;
|
||||
Main.regionalConditions.locName.clear();
|
||||
Main.regionalConditions.temperature.clear();
|
||||
Main.regionalConditions.condition.clear();
|
||||
for (int i = 0; i < regConIcaos.size(); i++) {
|
||||
Main.regionalConditions.locName.add(getLocName(regConNames.get(i)));
|
||||
Main.regionalConditions.temperature.add(getTemperature(regConIcaos.get(i), key));
|
||||
|
||||
@@ -4,90 +4,104 @@ import org.json.JSONObject;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RegionalForecast extends Thread {
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
ArrayList<String> locName = new ArrayList<>();
|
||||
ArrayList<String> condition = new ArrayList<>();
|
||||
ArrayList<String> low = new ArrayList<>();
|
||||
ArrayList<String> high = new ArrayList<>();
|
||||
String first;
|
||||
Utilities utl = new Utilities();
|
||||
|
||||
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) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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 "NO REPORT";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
|
||||
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0;
|
||||
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 "NO REPORT";
|
||||
}
|
||||
|
||||
String responseBody = response.body().string();
|
||||
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) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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);
|
||||
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);
|
||||
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) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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) ? 2 : 0;
|
||||
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);
|
||||
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() {
|
||||
ArrayList<String> regForNames = new ArrayList<>();
|
||||
regForNames.addAll(Main.regForNames);
|
||||
@@ -104,5 +118,7 @@ public class RegionalForecast extends Thread {
|
||||
Main.regionalForecast.low.add(getLow(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.Image;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class SlidesRunner extends Scene {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("h:mm:ss a");
|
||||
@@ -60,9 +58,8 @@ public class SlidesRunner extends Scene {
|
||||
GameObject cBumperTwo;
|
||||
Utilities utl = new Utilities();
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
ZonedDateTime today = ZonedDateTime.now();
|
||||
final String prefix = today.format(DateTimeFormatter.ofPattern("E MMM"));
|
||||
ZonedDateTime now = ZonedDateTime.now(Main.timeZone);
|
||||
final String prefix = now.format(DateTimeFormatter.ofPattern("E MMM"));
|
||||
|
||||
//slide line variables
|
||||
ArrayList<String> ccMainLines = new ArrayList<>();
|
||||
@@ -547,8 +544,7 @@ public class SlidesRunner extends Scene {
|
||||
}
|
||||
|
||||
public void dateTime() {
|
||||
now = LocalDateTime.now();
|
||||
today = ZonedDateTime.now();
|
||||
now = ZonedDateTime.now(Main.timeZone);
|
||||
|
||||
dateLine = utl.ljust(String.format("%s %2d", prefix, now.getDayOfMonth()).toUpperCase(), 10, " ") + utl.ljust(" ", 11, " ") + utl.rjust(now.format(formatter), 11, " ");
|
||||
|
||||
@@ -613,14 +609,20 @@ public class SlidesRunner extends Scene {
|
||||
CurrentConditions ctData = Main.currentConditions;
|
||||
|
||||
tickerLines.clear();
|
||||
tickerLines.add(utl.ljust(ctData.locName, 32, " "));
|
||||
tickerLines.add(utl.ljust(ctData.condition, 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, " "));
|
||||
|
||||
if (ctData.condition.equals("NO CURRENT REPORT")) {
|
||||
tickerLines.add(utl.ljust(ctData.locName, 32, " "));
|
||||
tickerLines.add(utl.ljust(ctData.condition, 32, " "));
|
||||
} else {
|
||||
tickerLines.add(utl.ljust(ctData.locName, 32, " "));
|
||||
tickerLines.add(utl.ljust(ctData.condition, 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() {
|
||||
slideRounds = 0;
|
||||
@@ -793,7 +795,7 @@ public class SlidesRunner extends Scene {
|
||||
}
|
||||
int wordlength = lfData.bulletin.get(i).length();
|
||||
if (wordlength + sb.length() + 1 <= 30) {
|
||||
if (!sb.isEmpty()) {sb.append(" ");}
|
||||
if (!(sb.length() == 0)) {sb.append(" ");}
|
||||
sb.append(lfData.bulletin.get(i));
|
||||
} else {
|
||||
i--;
|
||||
@@ -811,7 +813,7 @@ public class SlidesRunner extends Scene {
|
||||
for (int i = 0; i <= lfData.forecastOne.size()-1; i++) {
|
||||
int wordlength = lfData.forecastOne.get(i).length();
|
||||
if (wordlength + sb.length() + 1 <= 32) {
|
||||
if (!sb.isEmpty()) {sb.append(" ");}
|
||||
if (!(sb.length() == 0)) {sb.append(" ");}
|
||||
sb.append(lfData.forecastOne.get(i));
|
||||
} else {
|
||||
i--;
|
||||
@@ -825,7 +827,7 @@ public class SlidesRunner extends Scene {
|
||||
for (int i = 0; i <= lfData.forecastTwo.size()-1; i++) {
|
||||
int wordlength = lfData.forecastTwo.get(i).length();
|
||||
if (wordlength + sb.length() + 1 <= 32) {
|
||||
if (!sb.isEmpty()) {sb.append(" ");}
|
||||
if (!(sb.length() == 0)) {sb.append(" ");}
|
||||
sb.append(lfData.forecastTwo.get(i));
|
||||
} else {
|
||||
i--;
|
||||
@@ -839,7 +841,7 @@ public class SlidesRunner extends Scene {
|
||||
for (int i = 0; i <= lfData.forecastThree.size()-1; i++) {
|
||||
int wordlength = lfData.forecastThree.get(i).length();
|
||||
if (wordlength + sb.length() + 1 <= 32) {
|
||||
if (!sb.isEmpty()) {sb.append(" ");}
|
||||
if (!(sb.length() == 0)) {sb.append(" ");}
|
||||
sb.append(lfData.forecastThree.get(i));
|
||||
} else {
|
||||
i--;
|
||||
@@ -1018,11 +1020,21 @@ public class SlidesRunner extends Scene {
|
||||
rfMainLines.clear();
|
||||
|
||||
rfMainLines.add(" FORECAST ACROSS THE REGION ");
|
||||
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));
|
||||
|
||||
if (rfData.first.equals("L")) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1117,24 +1129,14 @@ public class SlidesRunner extends Scene {
|
||||
|
||||
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, " "));
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i <= oData.outlook.size()-1; i++) {
|
||||
int cwordlength = oData.outlook.get(i).length();
|
||||
if (cwordlength + sb.length() + 1 <= 32) {
|
||||
if (!sb.isEmpty()) {sb.append(" ");}
|
||||
sb.append(oData.outlook.get(i));
|
||||
} else {
|
||||
i--;
|
||||
olMainLines.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
}
|
||||
}
|
||||
olMainLines.add(utl.ljust(sb.toString(), 32, " "));
|
||||
olMainLines.add(utl.ljust(" ", 32, " "));
|
||||
olMainLines.add(" 30 DAY OUTLOOK ");
|
||||
olMainLines.add(oData.month);
|
||||
olMainLines.add(utl.ljust(" ", 32, " "));
|
||||
olMainLines.add("TEMPERATURES: " + oData.temperature);
|
||||
olMainLines.add(utl.ljust(" ", 32, " "));
|
||||
olMainLines.add("PRECIPITATION: " + oData.precipitation);
|
||||
|
||||
slideInit = true;
|
||||
}
|
||||
@@ -1144,7 +1146,7 @@ public class SlidesRunner extends Scene {
|
||||
int poolIdx = 0;
|
||||
|
||||
for (int row = 0; row < olMainLines.size(); row++) {
|
||||
int lineHeight = row == 1 ? 22 : 40;
|
||||
int lineHeight = 40;
|
||||
String line = olMainLines.get(row);
|
||||
for (int i = 0; i < line.length(); i ++) {
|
||||
if (poolIdx >= olPool.length) break;
|
||||
@@ -1232,15 +1234,6 @@ public class SlidesRunner extends Scene {
|
||||
}
|
||||
}
|
||||
|
||||
public void airportDelays() {
|
||||
slideRounds = 0;
|
||||
this.addGameObjectToScene(bg);
|
||||
|
||||
if (!slideInit) {
|
||||
slideInit = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void travelForecast() {
|
||||
travelForecastActive = true;
|
||||
this.addGameObjectToScene(travelBg);
|
||||
@@ -1250,13 +1243,25 @@ public class SlidesRunner extends Scene {
|
||||
travelMainLines.clear();
|
||||
travelMainLines.add(" TRAVEL CITIES FORECAST ");
|
||||
travelMainLines.add(utl.ljust(" ", 32, " "));
|
||||
travelMainLines.add("CITY WEATHER LOW HI");
|
||||
for (int i = 0; i < tfData.locName.size(); i++) {
|
||||
travelMainLines.add(utl.ljust(tfData.locName.get(i), 15, " ") +
|
||||
|
||||
if (tfData.first.equals("L")) {
|
||||
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.rjust(tfData.low.get(i), 3, " ") +
|
||||
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;
|
||||
travelOffset = 0;
|
||||
}
|
||||
|
||||
@@ -5,18 +5,20 @@ import util.Utilities;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import java.time.LocalDate;
|
||||
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<>();
|
||||
@@ -28,80 +30,75 @@ public class Tides extends Thread {
|
||||
DateTimeFormatter tideTimeFormatter = DateTimeFormatter.ofPattern("h:mma E", Locale.ENGLISH);
|
||||
|
||||
String getLocName(String displayName) {
|
||||
return utl.cjust(displayName, 32, " ").substring(0, 32);
|
||||
return utl.cjust(displayName, 32, " ").toUpperCase().substring(0, 32);
|
||||
}
|
||||
|
||||
String getTides(String station, String tide) {
|
||||
try {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.tidesandcurrents.noaa.gov/api/prod/datagetter?begin_date=" + LocalDate.now().format(tideDateFormatter) + "&end_date=" + LocalDate.now().plusDays(1).format(tideDateFormatter) + "&station=" + station + "&product=predictions&datum=MLLW&time_zone=lst_ldt&interval=hilo&units=english&application=DataAPI_Sample&format=json"))
|
||||
.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();
|
||||
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;
|
||||
}
|
||||
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 " ";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
|
||||
String getSunData(String icaoCode, String key, String type) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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();
|
||||
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 {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
}
|
||||
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
String time = JSONResponse.getJSONArray(type).getString(0);
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
return " ";
|
||||
}
|
||||
|
||||
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";
|
||||
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 " ";
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -12,93 +13,112 @@ import org.json.JSONObject;
|
||||
import util.Utilities;
|
||||
|
||||
public class TravelForecast extends Thread {
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
|
||||
ArrayList<String> locName = new ArrayList<>();
|
||||
ArrayList<String> condition = new ArrayList<>();
|
||||
ArrayList<String> low = new ArrayList<>();
|
||||
ArrayList<String> high = new ArrayList<>();
|
||||
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> 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){
|
||||
return utl.ljust(displayName, 14, " ").substring(0, 14);
|
||||
return utl.ljust(displayName, 14, " ").toUpperCase().substring(0, 14);
|
||||
}
|
||||
|
||||
String getCondition(String icaoCode, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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 "NO REPORT";
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
|
||||
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 2 : 0;
|
||||
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 "NO REPORT";
|
||||
}
|
||||
|
||||
String responseBody = response.body().string();
|
||||
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) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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);
|
||||
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);
|
||||
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) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
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) ? 2 : 0;
|
||||
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);
|
||||
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() {
|
||||
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++) {
|
||||
Main.travelForecast.locName.add(getLocName(tForNames.get(i)));
|
||||
Main.travelForecast.condition.add(getCondition(tForIcaos.get(i), key));
|
||||
Main.travelForecast.low.add(getLow(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";
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import static org.lwjgl.opengl.ARBTextureRectangle.*;
|
||||
|
||||
import static org.lwjgl.stb.STBImage.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.*;
|
||||
@@ -61,10 +62,17 @@ public class Texture {
|
||||
}
|
||||
|
||||
// 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);
|
||||
nativeBuffer.put(bytes);
|
||||
nativeBuffer.flip();
|
||||
((java.nio.Buffer) nativeBuffer).flip();
|
||||
|
||||
// Tell STB to decode the image from raw memory instead of a disk path
|
||||
image = stbi_load_from_memory(nativeBuffer, widthBuffer, heightBuffer, channelsBuffer, 0);
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
"Flash Flood Warning": { "headline": false, "scroll": true, "severity": "Warning" },
|
||||
"Excessive Heat Watch": { "headline": true, "scroll": true, "severity": "Advisory" },
|
||||
"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" },
|
||||
"Tropical Storm Watch": { "headline": true, "scroll": true, "severity": "Advisory" },
|
||||
"Tropical Storm Warning": { "headline": true, "scroll": true, "severity": "Warning" },
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
{"segment":"localForecast", "duration": 600.0},
|
||||
{"segment":"regionalForecast", "duration": 600.0},
|
||||
{"segment":"almanac", "duration": 600.0},
|
||||
{"segment":"regionalConditions", "duration": 600.0}
|
||||
{"segment":"hourlyObservations", "duration": 600.0}
|
||||
],
|
||||
"I": [
|
||||
{"segment":"currentConditions", "duration": 600.0},
|
||||
|
||||
Reference in new issue
Block a user