Weather library for Processing
Including weather information into Processing.


2012
UPDATE 12/10/19 We updated the library and are now using Yahoo’s service, hopefully they won’t shut down as well. The information is quiete similar, the API of the library changed a little though.

UPDATE 12/09/15 Google just announced to stop their Google weather API. Therefore the library will not work anymore. We are looking for some alternative services to hopefully update the library in the near future. More information at TheNextWeb.

While working on another project we needed to include weather information into Processing. The sketch that is running for weeks or even months has to change according to the local weather. Since there was no library for that purpose yet, we decided to write one ourselves and share it with people who might need it aswell The following will be an explanation of a short example, which will show you some basic functionalities of the library. For an overview on the library check the list of functions at the end of the article.

In the following example we simply print the weather information to the screen. Make sure to call the update() method every frame, otherwise your sketch will not be updated.

Note line 12:

weather = new YahooWeather(this, 638242, "c", updateIntervallMillis);

The second parameter, 638242, is the WOEID of Berlin. You unfortunately can’t just enter the name of the city, that’s simply how Yahoo’s weather API is built. In order to find out the WOEID of your or any other location go to http://weather.yahoo.com/, type in your location on the right and you will see the WOEID in your adress bar, http://weather.yahoo.com/germany/berlin/berlin-638242/.
The third parameter indicates the unit of the returned values. c stands for Celcius (European units) and f stands for Fahrenheit (American units). This classification not only applies to the degrees, aswell for pressure, distance etc. Look it up on http://developer.yahoo.com/weather/.
In the keyPressed method we change the city. This automatically updates the entire sketch.

processing codeYahoo Weather

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import com.onformative.yahooweather.*;

YahooWeather weather;
int updateIntervallMillis = 30000;

void setup() {
size(700, 300);
fill(0);
textFont(createFont(»Arial«, 14));
// 638242= the WOEID of Berlin
// use this site to find out about your WOEID : http://sigizmund.info/woeidinfo/
weather = new YahooWeather(this, 638242, "c", updateIntervallMillis);
}

void draw() {
weather.update();

background(255);
text("City: »+weather.getCityName()+"; Region: »+weather.getRegionName()+"; Country: »+weather.getCountryName()+"; Last updated: "+weather.getLastUpdated(), 20, 20);
text("Lon: "+weather.getLongitude()+" Lat: "+weather.getLatitude(), 20, 40);
text("WindTemp: "+weather.getWindTemperature()+" WindSpeed: »+weather.getWindSpeed()+" WindDirection: "+weather.getWindDirection(), 20, 60);
text("Humidity: "+weather.getHumidity()+" Visibility: "+weather.getVisibleDistance()+« pressure: "+weather.getPressure()+" rising: "+weather.getRising(), 20, 80);
text("Sunrise: "+weather.getSunrise()+" Sunset: "+weather.getSunset(), 20, 100);
}

public void keyPressed() {
if (key == 'q') {
weather.setWOEID(638242);
}
if (key == 'r') {
weather.setWOEID(44418);
}
if (key == 'w') {
weather.setTempertureUnit("c");
}
if (key == 'e') {
weather.setTempertureUnit("f");
}
}

List of all methods of the library:

void update();
void setWOEID(int WOEID);

void setTemperatureUnit(String unit);

Date getLastUpdated();
String getWeatherCondition();
int getWeatherConditionCode();
String getCityName();
String getCountryName();
String getRegionName();
float getLatitude();
float getLongitude();

int getTemperature();
int getHumidity();
int getWindTemperature();
float getWindSpeed();
int getWindDirection();
float getVisibleDistance();
float getPressure();
int getRising();
String getSunrise();
String getSunset();

Tomorrow

int getTemperatureLowTomorrow();
int getTemperatureHighTomorrow();
String getWeatherConditionTomorrow();
int getWeatherConditionCodeTomorrow();
String getWeekdayTomorrow();

Day after tomorrow

int getTemperatureLowDayAfterTomorrow();
int getTemperatureHighDayAfterTomorrow();
String getWeatherConditionDayAfterTomorrow();
int getWeatherConditionCodeDayAfterTomorrow();
String getWeekdayDayAfterTomorrow();
This method has to be called in the beginning of every frame.
Sets the WOEID(WHERE-ON-EARTH) of the retrieved weather data. See explanation above.
Sets the units for the weather report. »c« and »f« accepted.

Returns the full timestamp as Date of the last update.
The general weather condition.
The Code of the general weather. Check this for explanation.
Returns the city name of the requested WOEID.
The country in which the WOEID is located.
The region, if there is one.
The Latitude of the location.
The Longitude of the location.

Current temperature.
Current humidity.
Current wind temperture.
Current wind speed.
Current wind direction. 0=N, 90=,E 180=S, etc
Current visible distance.
Current pressure.
State of the barometric pressure: 0=steady, 1=rising, 2=falling
Time of sunrise.
Time of sunset.



Min temperature forecast for tomorrow.
Max temperature forecast for tomorrow.
General weather forecast for tomorrow
General weather code for tomorrow
The day of the week tomorrow.



Min temperature forecast for the day after tomorrow.
Max temperature forecast for the day after tomorrow.
General weather forecast for the day after tomorrow
General weather code for the day after tomorrow
The day of the week the day after tomorrow.
Attention: If you want any further explanation or information on the values check the developer site of the weather api from Yahoo here.
Reference

Have a look at the javadoc reference here. a copy of the reference is included in the .zip as well.