Skip to content

Instantly share code, notes, and snippets.

@rhathaway
Created December 3, 2011 22:33
Show Gist options
  • Save rhathaway/1428357 to your computer and use it in GitHub Desktop.
Save rhathaway/1428357 to your computer and use it in GitHub Desktop.
wunderground api data in processing
import com.francisli.processing.http.*;
HttpClient client;
void setup() {
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();
String locationInfo = results.get("current_observation").get("display_location").get("full").stringValue();
String currentTime = results.get("current_observation").get("observation_time").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();
println(locationInfo);
println(currentTime);
println("Current conditions: " + currentConditions);
println("Temperature: " + tempF + "° F / " + tempC + "° C");
}
}
void draw () {
}
@rhathaway
Copy link
Author

Console output:

San Francisco, CA
Last Updated on December 3, 2:33 PM PST
Current conditions: Partly Cloudy
Temperature: 66.9° F / 19.4° C

@positivelydoped23
Copy link

I am getting an error
"The type JSONObject is ambiguous"
Can you tell me what might that mean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment