diff --git a/src/main/java/edu/unl/cse/soft160/weatherexample/WeatherExample.java b/src/main/java/edu/unl/cse/soft160/weatherexample/WeatherExample.java new file mode 100644 index 0000000000000000000000000000000000000000..ca27f92cbec78e956fcd870cfd856a098715b59c --- /dev/null +++ b/src/main/java/edu/unl/cse/soft160/weatherexample/WeatherExample.java @@ -0,0 +1,41 @@ +package edu.unl.cse.soft160.weatherexample; + +import java.util.Date; + +import edu.unl.cse.soft160.json_connections.connection.RestConnection; +import edu.unl.cse.soft160.json_connections.connector.OpenWeatherConnector; + +import java.io.IOException; +import java.util.Calendar; + +public class WeatherExample { + public static long getEpochTime(int year, int month, int day, int hour, int minute, int second) { + Date date = new Calendar.Builder() + .setDate(year, month, day) + .setTimeOfDay(hour, minute, second) + .build().getTime(); + return date.getTime() / 1000; + } + + public static void main(String... args) { + String apiKey = ""; + try { + apiKey = RestConnection.getApiKey("openweathermap"); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } +// OpenWeatherConnector connector = new OpenWeatherConnector("weather", apiKey); + OpenWeatherConnector connector = new OpenWeatherConnector("weather"); + try { +// connector.retrieveData("zip=68588"); + connector.retrieveData("unl-oct24-0917.json"); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + System.out.println("It feels like: " + connector.getFeelsLike()); + System.out.println("Date of report: " + connector.getTimestamp()); + System.out.println("Epoch Time: " + getEpochTime(2021, Calendar.OCTOBER, 24, 9, 17, 33)); + } +} diff --git a/src/main/resources/weather/unl-oct24-0917.json b/src/main/resources/weather/unl-oct24-0917.json new file mode 100644 index 0000000000000000000000000000000000000000..2c0446cd0d41a347da315e26b8e9e74fc7cc2950 --- /dev/null +++ b/src/main/resources/weather/unl-oct24-0917.json @@ -0,0 +1,59 @@ +{ + "rain" : { + "1h" : 0.11 + }, + "visibility" : 8047, + "timezone" : -18000, + "main" : { + "temp" : 281.25, + "temp_min" : 279.77, + "humidity" : 96, + "pressure" : 1003, + "feels_like" : 279.92, + "temp_max" : 282.33 + }, + "clouds" : { + "all" : 90 + }, + "sys" : { + "country" : "US", + "sunrise" : 1635079694, + "sunset" : 1635118400, + "id" : 2017531, + "type" : 2 + }, + "dt" : 1635085053, + "coord" : { + "lon" : -96.6928, + "lat" : 40.8206 + }, + "weather" : [ + { + "icon" : "50d", + "description" : "mist", + "main" : "Mist", + "id" : 701 + }, + { + "icon" : "10d", + "description" : "light rain", + "main" : "Rain", + "id" : 500 + }, + { + "icon" : "11d", + "description" : "thunderstorm with light rain", + "main" : "Thunderstorm", + "id" : 200 + } + ], + "name" : "Lincoln", + "cod" : 200, + "id" : 0, + "base" : "stations", + "wind" : { + "deg" : 43, + "speed" : 2.24, + "gust" : 4.92 + } +}