Skip to content

Instantly share code, notes, and snippets.

@rhathaway
Created December 8, 2011 02:28
Show Gist options
  • Save rhathaway/1445841 to your computer and use it in GitHub Desktop.
Save rhathaway/1445841 to your computer and use it in GitHub Desktop.
wunderground in processing - display
import com.francisli.processing.http.*;
PFont cityFont, timeFont, weatherFont;
PImage backgroundImg;
PImage conditionImg;
PImage windImg;
String locationInfo, currentTime, currentConditions;
float tempF, tempC;
HttpClient client;
void setup() {
size(1024, 768);
frameRate(24);
cityFont = loadFont("UbuntuCondensed-Regular-45.vlw");
timeFont = loadFont("UbuntuCondensed-Regular-18.vlw");
weatherFont = loadFont("UbuntuCondensed-Regular-22.vlw");
backgroundImg = loadImage("weatherbg.jpg");
client = new HttpClient(this, "api.wunderground.com");
client.GET("/api/[api_key]/conditions/q/CA/San_Francisco.json");
}
void responseReceived(HttpRequest request, HttpResponse response) {
//// check for HTTP 200 success code
if (response.statusCode == 200) {
println(response.getContentAsString());
JSONObject results = response.getContentAsJSONObject();
// basic weather info
String locationInfo = results.get("current_observation").get("display_location").get("full").stringValue();
String currentTime = results.get("current_observation").get("observation_time_rfc822").stringValue();
float tempF = results.get("current_observation").get("temp_f").floatValue();
float tempC = results.get("current_observation").get("temp_c").floatValue();
String currentConditions = results.get("current_observation").get("weather").stringValue();
String iconURL = results.get("current_observation").get("icon_url").stringValue();
// wind info
String wind = results.get("current_observation").get("wind_string").stringValue();
String windDirection = results.get("current_observation").get("wind_dir").stringValue();
float windSpeed = results.get("current_observation").get("wind_mph").floatValue();
println(locationInfo);
println(currentTime);
println("Current conditions: " + currentConditions);
println("Temperature: " + tempF + "° F / " + tempC + "° C");
println(iconURL);
println("Wind conditions: " + wind);
println("Wind speed/direction: " + windSpeed + " MPH from the " + windDirection);
background(255);
imageMode(CORNERS);
image(backgroundImg, 0, 0);
textAlign(LEFT, TOP);
textFont(cityFont, 45);
fill(0, 200);
text(locationInfo, 15, 15);
textFont(timeFont, 18);
text(currentTime, 15, 60);
conditionImg = loadImage(iconURL);
image(conditionImg, 15, 110);
textFont(weatherFont, 22);
text(tempF + "° F / " + tempC + "° C", 75, 110);
text(currentConditions, 75, 135);
windImg = loadImage("wind-icon.gif");
image(windImg, 15, 185);
text("WIND: " + wind, 75, 185, 300, 60);
text("SPEED/DIRECTION: ", 75, 250);
text(windSpeed + " MPH from the " + windDirection, 75, 275);
}
}
void draw () {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment