Source for file YahooWeather.php
Documentation is available at YahooWeather.php
/* SVN FILE: $Id: YahooWeather.php 13 2009-10-13 13:36:59Z Chris $ */
* Yahoo! Weather data provider
* @link http://developer.yahoo.com/weather/ Yahoo Weather API documentation
* @copyright Copyright 2009 PBM Web Development - All Rights Reserved
* @package weatherForecast
* @subpackage weatherForecast.providers
* @version $Revision: 13 $
* @modifiedby $LastChangedBy: Chris $
* @lastmodified $Date: 2009-10-13 14:36:59 +0100 (Tue, 13 Oct 2009) $
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
include 'WeatherForecastProvider.php';
* Yahoo! Weather data provider
* <p>Values in params:<br>
* dateFormat (string) => Date format for days;
* Used by {@link http://www.yiiframework.com/doc/api/CDateFormatter#format-detail CDateFormatter::format()},
* see {@link http://www.unicode.org/reports/tr35/#Date_Format_Patterns Date Format Patterns}
* for a description of formats. Default: "EEE d' 'MMM yyyy"<br>
* location (string) => Location.<br>
* To find the location id follow the instructions on the Yahoo Developer Weather RSS page.<br>
* units (string) => Units to provide the forecast in.
* "C"|"F" C=metric (default), F=imperial</p>
* @package weatherForecast
* @subpackage weatherForecast.providers
* @var string Driver description
private $provider =
"Yahoo! Weather";
* @var string Yahoo! Weather feed
private $feed =
'http://weather.yahooapis.com/forecastrss?p=%s&u=%s';
* @var string Yahoo! Weather url
private $url =
'http://weather.yahoo.com/';
* @var string Default values
protected $defaults =
array(
'location' =>
'UKXX0085', //London
'dateFormat' =>
'EEE d MMM yyyy'
* @var array Maps weather codes to symbols
protected $symbolMap =
array(
3 =>
'thunderstorm_severe.png',
14 =>
'snow_showers.png',
27 =>
'partly_cloudy_night.png',
28 =>
'partly_cloudy_day.png',
29 =>
'partly_cloudy_night.png',
30 =>
'partly_cloudy_day.png',
34 =>
'partly_cloudy_day.png',
37 =>
'thunderstorm.png',
38 =>
'thunderstorm.png',
39 =>
'thunderstorm.png',
42 =>
'snow_showers.png',
44 =>
'partly_cloudy_day.png',
45 =>
'thunder_showers.png',
46 =>
'snow_showers.png',
47 =>
'thunder_showers.png',
* Fetches the forecast from the provider's datasource
* Required by IWeatherForecastProvider interface
* @return WFWeatherForecast Forecast object
$this->init($params, $symbols);
$dateFormatter =
Yii::app()->dateFormatter;
$contextNode =
$this->xpath->evaluate('/rss/channel')->item(0);
$forecast->provider =
CHtml::link($this->provider, $this->url, array('rel'=>
'external'));
$forecast->issued =
$this->xpath->evaluate('string(lastBuildDate)', $contextNode);
$distanceUnits =
$this->xpath->evaluate('string(yweather:units/@distance)', $contextNode);
$pressureUnits =
$this->xpath->evaluate('string(yweather:units/@pressure)', $contextNode);
$speedUnits =
$this->xpath->evaluate('string(yweather:units/@speed)', $contextNode);
$temperatureUnits =
$this->xpath->evaluate('string(yweather:units/@temperature)', $contextNode);
$forecast->location->name =
$this->xpath->evaluate('string(yweather:location/@city)', $contextNode);
$forecast->location->lat =
$this->xpath->evaluate('string(item/geo:lat)', $contextNode);
$forecast->location->long =
$this->xpath->evaluate('string(item/geo:long)', $contextNode);
$day->date =
'Current Conditions';
$day->sunrise =
$this->xpath->evaluate('string(yweather:astronomy/@sunrise)', $contextNode);
$day->sunset =
$this->xpath->evaluate('string(yweather:astronomy/@sunset)', $contextNode);
$day->description =
$this->xpath->evaluate('string(item/yweather:condition/@text)', $contextNode);
$day->symbol =
$this->symbolsDir .
$this->symbolMap[$this->xpath->evaluate('string(item/yweather:condition/@code)', $contextNode)];
$day->temperature->value =
$this->xpath->evaluate('string(item/yweather:condition/@temp)', $contextNode);
$day->temperature->units =
$temperatureUnits;
$day->windSpeed->value =
$this->xpath->evaluate('string(yweather:wind/@speed)', $contextNode);
$day->windSpeed->units =
$speedUnits;
$day->windDirection->value =
$this->xpath->evaluate('string(yweather:wind/@direction)', $contextNode);
$day->windDirection->units =
'°';
$day->humidity->value =
$this->xpath->evaluate('string(yweather:atmosphere/@humidity)', $contextNode);
$day->humidity->units =
$humidityUnits;
$day->visibility->value =
$this->xpath->evaluate('string(yweather:atmosphere/@visibility)', $contextNode)/
100;
$day->visibility->units =
$distanceUnits;
$day->pressure->value =
$this->xpath->evaluate('string(yweather:atmosphere/@pressure)', $contextNode);
$day->pressure->units =
$pressureUnits;
$forecast->days->add(0, $day);
$items =
$this->xpath->evaluate('item/yweather:forecast', $contextNode);
for ($i =
0, $l =
$items->length; $i <
$l;) {
$contextNode =
$items->item($i++
);
$day->date =
$dateFormatter->format($this->dateFormat, $this->xpath->evaluate('string(@date)', $contextNode));
$day->description =
$this->xpath->evaluate('string(@text)', $contextNode);
$day->symbol =
$this->symbolsDir .
$this->symbolMap[$this->xpath->evaluate('string(@code)', $contextNode)];
$day->maxTemperature->value =
$this->xpath->evaluate('string(@high)', $contextNode);
$day->maxTemperature->units =
$temperatureUnits;
$day->minTemperature->value =
$this->xpath->evaluate('string(@low)', $contextNode);
$day->minTemperature->units =
$temperatureUnits;
$forecast->days->add($i, $day);
* Parses the pressure trend into words
* @param DOMNode $contextNode The node from with to start XPath evaluation
* @return string The pressure trend
switch ($this->xpath->evaluate('string(yweather:atmosphere/@rising)', $contextNode)) {
Documentation generated on Tue, 13 Oct 2009 14:44:52 +0100 by phpDocumentor 1.4.2