Yahoo Weather : Some classes to make it easier to get what you want
in
Share your Work
•
3 months ago
//hey folks I just put this together for something I was making - it's a pretty simple thing to do but I'm sure this job gets repeated a lot so thought I'd post it- please let me have any criticism or corrections
//yahoo_weather_example Copyright (C) <2012> <Tom Schofield>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program. If not, see <
http://www.gnu.org/licenses/>
YahooWeather weather;
void setup() {
size(100, 100);
// Make a WeatherGrabber object
//you can find woeids at
http://isithackday.com/geoplanet-explorer/index.php?woeid=560743
String glasgowWOEID ="22465834";
String dublinWOEID ="560743";
String skegnessWOEID ="34892";
String genovaWOEID ="712516";
//make a new weather object with this WOEID
weather = new YahooWeather(skegnessWOEID);
// Tell it to request the weather
weather.getWeather();
//here's what you can get
String weatherReport ="title is: ";
weatherReport+=weather.getTitle();
weatherReport+="\nlat is: ";
weatherReport+=str(weather.getLatLong().x);
weatherReport+="\nlong is: ";
weatherReport+=str(weather.getLatLong().y);
weatherReport+="\npubdate is:";
weatherReport+=weather.getPubDate();
weatherReport+="\nweather code for today is; ";
weatherReport+=str(weather.getTodaysCode());
weatherReport+="\ntoday's data is: ";
weatherReport+=weather.getTodaysDate();
weatherReport+="\ntoday's temp is: ";
weatherReport+=str(weather.getTodaysTemp());
weatherReport+="\ntoday's weather is: ";
weatherReport+=weather.getTodaysText();
weatherReport+="\ntommorw's code is: ";
weatherReport+=str(weather.getForecastCode(1));
weatherReport+="\ntommorw's date is: ";
weatherReport+=weather.getForecastDate(1);
weatherReport+="\ntommorw's day is: ";
weatherReport+=weather.getForecastDay(1);
weatherReport+="\ntommorw's high is: ";
weatherReport+=str(weather.getForecastHigh(1));
weatherReport+="\ntommorw's low is: ";
weatherReport+=str(weather.getForecastLow(1));
weatherReport+="\ntommorw's weather is: ";
weatherReport+=weather.getForecastText(1);
println(weatherReport);
}
//functions for todays weather
int getTodaysCode() {
return yWeathers[0].getCode();
}
String getTodaysDate() {
return yWeathers[0].getDate();
}
int getTodaysTemp() {
return yWeathers[0].getTemp();
}
String getTodaysText() {
return yWeathers[0].getText();
}
//functions for forecast weather
int getForecastCode(int numDaysAhead) {
return yWeathers[numDaysAhead].getCode();
}
String getForecastDate(int numDaysAhead) {
return yWeathers[numDaysAhead].getDate();
}
String getForecastDay(int numDaysAhead) {
return yWeathers[numDaysAhead].getDay();
}
int getForecastHigh(int numDaysAhead) {
return yWeathers[numDaysAhead].getHigh();
}
int getForecastLow(int numDaysAhead) {
return yWeathers[numDaysAhead].getLow();
}
String getForecastText(int numDaysAhead) {
return yWeathers[numDaysAhead].getText();
}
}
class YWeather{
//example contents code="32" date="13 Jul 2013" day="Sat" high="84" low="68" text="Sunny"
int code;
String date;
String day;
int high;
int low;
String text;
int temp;
boolean isForecast;
YWeather(int _code,String _date,String _day,int _high, int _low, String _text, int _temp, boolean _isForecast){
code=_code;
date=_date;
day =_day;
high=_high;
low=_low;
text=_text;
temp=_temp;
isForecast = _isForecast;
}
int getCode(){
return code;
}
String getDate(){
return date;
}
String getDay(){
return day;
}
int getHigh(){
return high;
}
int getLow(){
return low;
}
String getText(){
return text;
}
int getTemp(){
return temp;
}
}
1