Created
December 11, 2011 21:24
-
-
Save rhathaway/1462829 to your computer and use it in GitHub Desktop.
wunderground in processing with data for 4 cities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.francisli.processing.http.*; | |
PFont cityFont, timeFont, weatherFont; | |
PImage backgroundImg; | |
PImage conditionImg; | |
PImage windImg; | |
String locationInfo, currentTime, currentConditions, iconURL, wind, windDirection; | |
float tempF, tempC, windSpeed; | |
// variables for specific city data | |
String HNLinfo, HNLtime, HNLconditions, HNLwind, HNLwindDirection, HNLiconURL; | |
float HNLtempF, HNLtempC, HNLwindSpeed; | |
String SFOinfo, SFOtime, SFOconditions, SFOwind, SFOwindDirection, SFOiconURL; | |
float SFOtempF, SFOtempC, SFOwindSpeed; | |
String CHIinfo, CHItime, CHIconditions, CHIwind, CHIwindDirection, CHIiconURL; | |
float CHItempF, CHItempC, CHIwindSpeed; | |
String NYCinfo, NYCtime, NYCconditions, NYCwind, NYCwindDirection, NYCiconURL; | |
float NYCtempF, NYCtempC, NYCwindSpeed; | |
HttpClient client; | |
HttpRequest HNLweather, SFOweather, CHIweather, NYCweather; | |
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"); | |
HNLweather = client.GET("/api/[api_key]/conditions/q/HI/Honolulu.json"); | |
SFOweather = client.GET("/api/[api_key]/conditions/q/CA/San_Francisco.json"); | |
CHIweather = client.GET("/api/[api_key]/conditions/q/IL/Chicago.json"); | |
NYCweather = client.GET("/api/[api_key]/conditions/q/NY/New_York_City.json"); | |
} | |
void responseReceived(HttpRequest request, HttpResponse response) { | |
//// check for HTTP 200 success code | |
if (response.statusCode == 200) { | |
println(response.getContentAsString()); | |
JSONObject results = response.getContentAsJSONObject(); | |
locationInfo = results.get("current_observation").get("display_location").get("full").stringValue(); | |
currentTime = results.get("current_observation").get("observation_time_rfc822").stringValue(); | |
tempF = results.get("current_observation").get("temp_f").floatValue(); | |
tempC = results.get("current_observation").get("temp_c").floatValue(); | |
currentConditions = results.get("current_observation").get("weather").stringValue(); | |
iconURL = results.get("current_observation").get("icon_url").stringValue(); | |
// wind info | |
wind = results.get("current_observation").get("wind_string").stringValue(); | |
windDirection = results.get("current_observation").get("wind_dir").stringValue(); | |
windSpeed = results.get("current_observation").get("wind_mph").floatValue(); | |
if (request == HNLweather) { | |
HNLinfo = locationInfo.toUpperCase(); | |
HNLtime = currentTime; | |
HNLtempF = tempF; | |
HNLtempC = tempC; | |
HNLconditions = currentConditions; | |
HNLiconURL = iconURL; | |
HNLwind = wind; | |
HNLwindDirection = windDirection; | |
HNLwindSpeed = windSpeed; | |
println(HNLinfo); | |
println(HNLtime); | |
println("Current conditions: " + HNLconditions); | |
println("Temperature: " + HNLtempF + "° F / " + HNLtempC + "° C"); | |
println(HNLiconURL); | |
println("Wind conditions: " + HNLwind); | |
println("Wind speed/direction: " + HNLwindSpeed + " MPH from the " + HNLwindDirection); | |
background(255); | |
imageMode(CORNERS); | |
image(backgroundImg, 0, 0); | |
textAlign(LEFT, TOP); | |
textFont(cityFont, 45); | |
fill(0, 200); | |
text(HNLinfo, 15, 15); | |
textFont(timeFont, 18); | |
text(HNLtime, 15, 65); | |
conditionImg = loadImage(SFOiconURL); | |
image(conditionImg, 15, 110); | |
textFont(weatherFont, 22); | |
text(HNLtempF + "° F / " + HNLtempC + "° C", 75, 110); | |
text(HNLconditions, 75, 135); | |
windImg = loadImage("wind-icon.gif"); | |
image(windImg, 15, 185); | |
text("WIND: " + HNLwind, 75, 185, 300, 60); | |
text("SPEED/DIRECTION: ", 75, 250); | |
text(HNLwindSpeed + " MPH from the " + HNLwindDirection, 75, 275); | |
} | |
if (request == SFOweather) { | |
SFOinfo = locationInfo.toUpperCase(); | |
SFOtime = currentTime; | |
SFOtempF = tempF; | |
SFOtempC = tempC; | |
SFOconditions = currentConditions; | |
SFOiconURL = iconURL; | |
SFOwind = wind; | |
SFOwindDirection = windDirection; | |
SFOwindSpeed = windSpeed; | |
println(SFOinfo); | |
println(SFOtime); | |
println("Current conditions: " + SFOconditions); | |
println("Temperature: " + SFOtempF + "° F / " + SFOtempC + "° C"); | |
println(SFOiconURL); | |
println("Wind conditions: " + SFOwind); | |
println("Wind speed/direction: " + SFOwindSpeed + " MPH from the " + SFOwindDirection); | |
background(255); | |
imageMode(CORNERS); | |
image(backgroundImg, 0, 0); | |
textAlign(LEFT, TOP); | |
textFont(cityFont, 45); | |
fill(0, 200); | |
text(SFOinfo, 15, 15); | |
textFont(timeFont, 18); | |
text(SFOtime, 15, 65); | |
conditionImg = loadImage(SFOiconURL); | |
image(conditionImg, 15, 110); | |
textFont(weatherFont, 22); | |
text(SFOtempF + "° F / " + SFOtempC + "° C", 75, 110); | |
text(SFOconditions, 75, 135); | |
windImg = loadImage("wind-icon.gif"); | |
image(windImg, 15, 185); | |
text("WIND: " + SFOwind, 75, 185, 300, 60); | |
text("SPEED/DIRECTION: ", 75, 250); | |
text(SFOwindSpeed + " MPH from the " + SFOwindDirection, 75, 275); | |
} | |
if (request == CHIweather) { | |
CHIinfo = locationInfo.toUpperCase(); | |
CHItime = currentTime; | |
CHItempF = tempF; | |
CHItempC = tempC; | |
CHIconditions = currentConditions; | |
CHIiconURL = iconURL; | |
CHIwind = wind; | |
CHIwindDirection = windDirection; | |
CHIwindSpeed = windSpeed; | |
println(CHIinfo); | |
println(CHItime); | |
println("Current conditions: " + CHIconditions); | |
println("Temperature: " + CHItempF + "° F / " + CHItempC + "° C"); | |
println(CHIiconURL); | |
println("Wind conditions: " + CHIwind); | |
println("Wind speed/direction: " + CHIwindSpeed + " MPH from the " + CHIwindDirection); | |
background(255); | |
imageMode(CORNERS); | |
image(backgroundImg, 0, 0); | |
textAlign(LEFT, TOP); | |
textFont(cityFont, 45); | |
fill(0, 200); | |
text(CHIinfo, 15, 15); | |
textFont(timeFont, 18); | |
text(CHItime, 15, 65); | |
conditionImg = loadImage(CHIiconURL); | |
image(conditionImg, 15, 110); | |
textFont(weatherFont, 22); | |
text(CHItempF + "° F / " + CHItempC + "° C", 75, 110); | |
text(CHIconditions, 75, 135); | |
windImg = loadImage("wind-icon.gif"); | |
image(windImg, 15, 185); | |
text("WIND: " + CHIwind, 75, 185, 300, 60); | |
text("SPEED/DIRECTION: ", 75, 250); | |
text(CHIwindSpeed + " MPH from the " + CHIwindDirection, 75, 275); | |
} | |
if (request == NYCweather) { | |
NYCinfo = locationInfo.toUpperCase(); | |
NYCtime = currentTime; | |
NYCtempF = tempF; | |
NYCtempC = tempC; | |
NYCconditions = currentConditions; | |
NYCiconURL = iconURL; | |
NYCwind = wind; | |
NYCwindDirection = windDirection; | |
NYCwindSpeed = windSpeed; | |
println(NYCinfo); | |
println(NYCtime); | |
println("Current conditions: " + NYCconditions); | |
println("Temperature: " + NYCtempF + "° F / " + NYCtempC + "° C"); | |
println(NYCiconURL); | |
println("Wind conditions: " + NYCwind); | |
println("Wind speed/direction: " + NYCwindSpeed + " MPH from the " + NYCwindDirection); | |
background(255); | |
imageMode(CORNERS); | |
image(backgroundImg, 0, 0); | |
textAlign(LEFT, TOP); | |
textFont(cityFont, 45); | |
fill(0, 200); | |
text(NYCinfo, 15, 15); | |
textFont(timeFont, 18); | |
text(NYCtime, 15, 65); | |
conditionImg = loadImage(NYCiconURL); | |
image(conditionImg, 15, 110); | |
textFont(weatherFont, 22); | |
text(NYCtempF + "° F / " + NYCtempC + "° C", 75, 110); | |
text(NYCconditions, 75, 135); | |
windImg = loadImage("wind-icon.gif"); | |
image(windImg, 15, 185); | |
text("WIND: " + NYCwind, 75, 185, 300, 60); | |
text("SPEED/DIRECTION: ", 75, 250); | |
text(NYCwindSpeed + " MPH from the " + NYCwindDirection, 75, 275); | |
} | |
} | |
} | |
void draw () { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment