Presenting the YWeather API
I was designing a site this weekend when I needed some weather data. I started looking for solutions - I found phpweather and I found it to be an excellent tool. However, when I tried to query some "less" known cities, it returned nothing. One of the cities that I wanted the data for did not exist and I was disappointed.
Knowing that I can use sites like the weather network and get the weather data, I figured I might as well write my own class to fill this void. Thus was born the YWeather. YWeather is a php class that provides a class interface to access data from Yahoo Weather. It makes use of the Yahoo weather RSS feed.
The YWeather class uses MagpieRSS to parse through the RSS feed. When a location id is specified, the class parses the feed and gives a class interface to the weather data, making it easy to integrate to any web application.
Here is a test script I created to test the class, this list provides a list of the features of the class (I am too lazy to type this out :P)
The Yahoo feed provides 2 days forecast:
The class may be downloaded from here.
downloads/YWeather_w_magpie.zip
Knowing that I can use sites like the weather network and get the weather data, I figured I might as well write my own class to fill this void. Thus was born the YWeather. YWeather is a php class that provides a class interface to access data from Yahoo Weather. It makes use of the Yahoo weather RSS feed.
The YWeather class uses MagpieRSS to parse through the RSS feed. When a location id is specified, the class parses the feed and gives a class interface to the weather data, making it easy to integrate to any web application.
Here is a test script I created to test the class, this list provides a list of the features of the class (I am too lazy to type this out :P)
$w = new YWeather("CAXX0504");
"URL: ".$w->getURL()
"Title: ".$w->getTitle()
"Skies: ".$w->getSkies()
"Skies Image:
getImage($w->getSkies())."' />"
"Temperature: ".$w->getTemperature()
"Latitude: ".$w->getLat()
"Longitude: ".$w->getLong()
"isPM: ".$w->isPM()
"Published date: ".$w->getPublishDate()
"Description: ".$w->getDescription()
"Current Conditions: ".$w->getCurrentConditions()
"Forecasts: ".$w->getForecastsText()
The Yahoo feed provides 2 days forecast:
$forecasts = $w->getForecasts();
"Forecast 0 Day: ".$forecasts[0]['day']
"Forecast 0 Skies: ".$forecasts[0]['skies']
"Forecast 0 Skies Image:
getImage($forecasts[0]['skies'])."' />"
"Forecast 0 High: ".$forecasts[0]['high']
"Forecast 0 Low: ".$forecasts[0]['low']
"Forecast 1 Day: ".$forecasts[1]['day']
"Forecast 1 Skies: ".$forecasts[1]['skies']
"Forecast 1 Skies Image:
getImage($forecasts[1]['skies'])."' />"
"Forecast 1 High: ".$forecasts[1]['high']
"Forecast 1 Low: ".$forecasts[1]['low']The class may be downloaded from here.
downloads/YWeather_w_magpie.zip
0 Comments:
Post a Comment
<< Home