Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'aarons-master'

  • Loading branch information...
commit 46f907a84a15312943db3d944604b9ddb1b2c31c 2 parents 74d7bb6 + aa9fa35
Nolan Caudill authored
4 www/include/lib_api_privatesquare_venues.php
View
@@ -89,9 +89,9 @@ function api_privatesquare_venues_checkin(){
if (($GLOBALS['cfg']['enable_feature_weather_tracking']) && (! isset($checkin['created']))){
- loadlib("weather_google");
+ loadlib("weather_yahoo");
- $rsp = weather_google_conditions($checkin['latitude'], $checkin['longitude']);
+ $rsp = weather_yahoo_conditions($checkin['latitude'], $checkin['longitude'], $checkin['locality']);
if ($rsp['ok']){
$conditions = $rsp['conditions'];
57 www/include/lib_weather_yahoo.php
View
@@ -0,0 +1,57 @@
+<?php
+
+ loadlib("geo_utils");
+ loadlib("http");
+
+ $GLOBALS['weather_yahoo_endpoint'] = 'http://weather.yahooapis.com/forecastrss';
+
+ #################################################################
+
+ function weather_yahoo_conditions($lat, $lon, $woe_id){
+
+ $query = array();
+ $query['w'] = $woe_id;
+
+ $url = $GLOBALS['weather_yahoo_endpoint'] . "?" . http_build_query($query);
+
+ $rsp = http_get($url);
+
+ if (! $rsp['ok']){
+ return $rsp;
+ }
+
+ $doc = new SimpleXMLElement($rsp['body']);
+ $doc->registerXPathNamespace('yweather', 'http://xml.weather.yahoo.com/ns/rss/1.0');
+ $conditions = $doc->xpath('//yweather:condition');
+ $wind_conds = $doc->xpath('//yweather:wind');
+ $atmosphere_conds = $doc->xpath('//yweather:atmosphere');
+
+ if (! $conditions){
+ return not_okay("failed to parse conditions");
+ }
+
+ $condition_attrs = $conditions[0]->attributes();
+ $wind_attrs = $wind_conds[0]->attributes();
+ $atmosphere_attrs = $atmosphere_conds[0]->attributes();
+
+ $normalized_conds = array();
+ $normalized_conds['condition'] = (string)$condition_attrs['text'];
+ $normalized_conds['temp_f'] = (string)$condition_attrs['temp'];
+ $normalized_conds['temp_c'] = round(($normalized_conds['temp_f'] - 32) * (5/9));
+ $normalized_conds['wind'] = (string)$wind_attrs['speed'] . " mph";
+ $normalized_conds['humidity'] = (string)$atmosphere_attrs['humidity'] . '%';
+
+ $rsp = array(
+ 'latitude' => $lat,
+ 'longitude' => $lon,
+ 'timestamp' => time(),
+ 'source' => 'yahoo',
+ 'conditions' => $normalized_conds,
+ );
+
+ return okay($rsp);
+ }
+
+ #################################################################
+
+?>
4 www/templates/inc_weather_stringify.txt
View
@@ -1,7 +1,7 @@
<span class="weather">
{if $short_form}
-{if $weather.source=='google'}
+{if $weather.source=='google' || $weather.source=='yahoo'}
{if $cfg.weather_tracking_measure=='US'}
<span class="weather_temp">{$weather.temp_f|escape}° F</span><span class="weather_condition"> {$weather.condition|strtolower|escape}</span>
@@ -13,7 +13,7 @@
{else}
-{if $weather.source=='google'}
+{if $weather.source=='google' || $weather.source=='yahoo'}
{if $cfg.weather_tracking_measure=='US'}
<span class="weather_temp">It was {$weather.temp_f|escape}° F</span><span class="weather_condition"> and {$weather.condition|strtolower|escape}</span>
Please sign in to comment.
Something went wrong with that request. Please try again.