8.5.09

weather in twelve cities


//weather for twelve cities!

import simpleML.*;

XMLRequest aberdeen;
XMLRequest aberystwyth;
XMLRequest birmingham;
XMLRequest bristol;
XMLRequest dundee;
XMLRequest leeds;
XMLRequest liverpool;
XMLRequest london;
XMLRequest manchester;
XMLRequest newcastle;
XMLRequest oxford;
XMLRequest reading;



int startTime; //create timer
int counter = 0;


void setup() {
size(200,200);
//create and start up request

aberdeen = new XMLRequest(this,"http://weather.yahooapis.com/forecastrss?p=UKXX0001&u=c");
aberdeen.makeRequest();

aberystwyth = new XMLRequest(this,"http://weather.yahooapis.com/forecastrss?p=UKXX0203&u=c");
aberystwyth.makeRequest();

birmingham = new XMLRequest(this,"http://weather.yahooapis.com/forecastrss?p=UKXX0018&u=c");
birmingham.makeRequest();

bristol = new XMLRequest(this,"http://weather.yahooapis.com/forecastrss?p=UKXX0025&u=c");
bristol.makeRequest();

dundee = new XMLRequest(this,"http://weather.yahooapis.com/forecastrss?p=UKXX0045&u=c");
dundee.makeRequest();

leeds = new XMLRequest(this,"http://weather.yahooapis.com/forecastrss?p=UKXX0078&u=c");
leeds.makeRequest();

liverpool = new XMLRequest(this,"http://weather.yahooapis.com/forecastrss?p=UKXX0083&u=c");
liverpool.makeRequest();

london = new XMLRequest(this,"http://weather.yahooapis.com/forecastrss?p=UKXX0085&u=c");
london.makeRequest();

manchester = new XMLRequest(this,"http://weather.yahooapis.com/forecastrss?p=UKXX0092&u=c");
manchester.makeRequest();

newcastle = new XMLRequest(this,"http://weather.yahooapis.com/forecastrss?p=UKXX0098&u=c");
newcastle.makeRequest();

oxford = new XMLRequest(this,"http://weather.yahooapis.com/forecastrss?p=UKXX0106&u=c");
oxford.makeRequest();

reading = new XMLRequest(this,"http://weather.yahooapis.com/forecastrss?p=UKXX0117&u=c");
reading.makeRequest();
startTime = millis();//more timer stuff



}

void draw() {
background(0);

//every 5 seconds, make new request
int now = millis();

if (now - startTime > 5000) {
aberdeen.makeRequest();
println("1");
}

if (now - startTime > 5000) {
aberystwyth.makeRequest();
println("2");
}

if (now - startTime > 5000) {
birmingham.makeRequest();
println("3");
}

if (now - startTime > 5000) {
bristol.makeRequest();
println("4");
}

if (now - startTime > 5000) {
dundee.makeRequest();
println("5");
}

if (now - startTime > 5000) {
leeds.makeRequest();
println("6");
}

if (now - startTime > 5000) {
liverpool.makeRequest();
println("7");
}

if (now - startTime > 5001) {
london.makeRequest();
println("8");
}

if (now - startTime > 5000) {
manchester.makeRequest();
println("9");
}

if (now - startTime > 5000) {
newcastle.makeRequest();
println("10");
}

if (now - startTime > 5000) {
oxford.makeRequest();
println("11");
}

if (now - startTime > 5000) {
reading.makeRequest();
println("12");
startTime = now;
}


}


//when request is complete
void netEvent(XMLRequest ml) {

String city = ml.getElementAttributeText("yweather:location", "city");

String temp = ml.getElementAttributeText("yweather:condition", "temp");


String weather = ml.getElementAttributeText("yweather:condition","text");


if (weather.equals("Partly Cloudy")) {
println("Partly Cloudy" + city);

}

if (weather.equals("Partly Cloudy/Windy")) {
println("Partly Cloudy/Windy" + city);

}

if (weather.equals("Cloudy")) {
println("cloudy" + city);

}

if (weather.equals("Mostly Cloudy")) {
println("Mostly Cloudy" + city);

}

if (weather.equals("Mostly Cloudy/Windy")) {
println("Mostly Cloudy/Windy" + city);

}

if (weather.equals("Light Rain")) {
println("Light Rain" + city);

}

if (weather.equals("Light Rain/Wind")) {
println("Light Rain/Wind" + city);

}

if (weather.equals("Light Rain Shower")) {
println("Light Rain Shower" + city);
}

if (weather.equals("Rain")) {
println("Rain" + city);
}

if (weather.equals("Rain/Wind")) {
println("Rain/Wind" + city);
}

if (weather.equals("Few Showers")) {
println("Few Showers" + city);
}

if (weather.equals("Showers in the Vicinity")) {
println("Showers in the Vicinity" + city);
}

if (weather.equals("Sunny")) {
println("Sunny" + city);
}

if (weather.equals("Fair")) {
println("Fair" + city);
}

if (weather.equals("Moslty Sunny")) {
println("Mostly Sunny" + city);



}

}


Making progress :D

In the final code it will only refresh the RSS feed every few minutes, at the moment I'm keeping it in seconds so it's easier to see what's going on quickly.

0 comments: