Skip to content
Snippets Groups Projects
Commit 8851fcf7 authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

added example code

parent 26f3ea9e
No related branches found
No related tags found
No related merge requests found
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));
}
}
{
"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
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment