Files
citizen/Weather.pde

44 lines
1.2 KiB
Plaintext

PVector v2_coordinates = new PVector(48.799337, 9.794482); //badmauer; x: latitude, y: longitude
boolean b_isRaining;
String S_sunrise;
String S_sunset;
Date d_sunrise;
void initWeather(){
//sunrise / sunset API: https://sunrise-sunset.org/api
JSONObject sun;
if(b_loadSun) sun = loadJSONObject("https://api.sunrise-sunset.org/json?lat=" + v2_coordinates.x + " &lng=" + v2_coordinates.y);
else sun = loadJSONObject(dataPath("weather/today.json"));
//println(sun);
if (sun == null) {
//println("JSONObject could not be parsed");
} else {
JSONObject results = sun.getJSONObject("results");
S_sunrise = results.getString("sunrise");
S_sunset = results.getString("sunset");
}
}
/* backup json today (if api has yet to encounter limits)
{
"results": {
"sunrise": "7:13:29 AM",
"solar_noon": "11:25:52 AM",
"day_length": "08:24:45",
"astronomical_twilight_end": "5:33:03 PM",
"astronomical_twilight_begin": "5:18:41 AM",
"sunset": "3:38:14 PM",
"civil_twilight_end": "4:14:48 PM",
"nautical_twilight_end": "4:54:50 PM",
"civil_twilight_begin": "6:36:55 AM",
"nautical_twilight_begin": "5:56:54 AM"
},
"status": "OK"
}
*/