diff -Naur weather.svn/includes/objects/Forecast.php weather/includes/objects/Forecast.php
--- weather.svn/includes/objects/Forecast.php 2007-08-05 12:17:46.000000000 +0200
+++ weather/includes/objects/Forecast.php 2007-08-05 12:00:24.000000000 +0200
@@ -24,19 +24,13 @@
var $HighTemperature;
var $LowTemperature;
- function Forecast($date, $real_dayofweek) {
+ function Forecast($date,$d) {
+ $i = strpos($date, "/");
+ $j = strpos($date, "/", $i+1);
+ $month = substr($date,0,$i);
+ $day = substr($date,$i+1,$j-$i-1);
+ $year = substr($date,$j+1,2);
- $month = substr($date,0,2);
- $day = substr($date,3,2);
- $year = substr($date,6,4);
-
- $temp_date = mktime(0,0,0,$month,$day,$year);
- $date_time_array = getdate( $temp_date );
- $claimed_dayofweek = $date_time_array['wday'];
-
- if ($real_dayofweek != $claimed_dayofweek)
- $this->date = date('m/d/Y', mktime(0, 0, 0, $month , $day+1, $year));
- else
- $this->date = $date;
+ $this->date = date('m/d/Y', mktime(0,0,0,$month,$day+$d,$year));
}
}
diff -Naur weather.svn/includes/objects/WeatherSite.php weather/includes/objects/WeatherSite.php
--- weather.svn/includes/objects/WeatherSite.php 2007-08-05 12:17:46.000000000 +0200
+++ weather/includes/objects/WeatherSite.php 2007-08-05 12:00:24.000000000 +0200
@@ -51,78 +51,96 @@
$this->RadarImage = $this->getRadarURL();
}
+ function in($One,$Two,$data) {
+ $x = strpos($data,$One) + strlen($One);
+
+ if($x == false) {
+ return "N/A";
+ }
+
+ $y = strpos($data,$Two,$x);
+
+ if($y == false) {
+ return "N/A";
+ }
+
+ $str = substr($data, $x, $y - $x);
+ return $str;
+ }
+
function getData() {
global $Weather_Types;
- $data = @file('http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=' . $this->acid);
+ $data=join('',file("http://xoap.weather.com/weather/local/".$this->acid."?cc=*&unit=F&dayf=5"));
if ($data === FALSE)
return;
- foreach($data as $line) {
- if(strpos($line, 'this.sw') === false)
- continue;
- if(strpos($line, 'swTempCel') !== false)
- continue;
-
- $line = trim($line);
- list($name, $value) = explode(' = "', $line);
- $name = substr($name, 7);
- $value = substr($value, 0, strlen($value) - 2);
-
- switch ($name) {
- case 'City': $this->city = $value; break;
- case 'SubDiv': $this->subdiv = $value; break;
- case 'Country': $this->country = $value; break;
- case 'Region': $this->region = $value; break;
- case 'Temp': $this->Temperature = $value; break;
- case 'CIcon': $this->CIcon = $value; break;
- case 'WindS': $this->WindSpeed = $value; break;
- case 'WindD': $this->WindDirection = $value; break;
- case 'Baro': $this->BarometricPressure = $value; break;
- case 'Humid': $this->Humidity = $value; break;
- case 'Real': $this->Real = $value; break;
- case 'UV': $this->UV = $value; break;
- case 'Vis': $this->Visibility = $value; break;
- case 'LastUp': $this->LastUpdated = $value; break;
- case 'ConText': $this->ConText = $value; break;
- case 'Fore': $this->Forecast = $this->readForecast($value); break;
- default: /* Weird, unknown type */ break;
- }
- }
+ + //
+ // Technically we should include the partner id and key
+ // if this stops working, change to the following:
+ // http://xoap.weather.com/weather/local/".$this->acid."?cc=*&unit=F&dayf=5&prod=xoap&par=1036905921&key=f68c2657a4fd3e2e"
+ // may need to get a new one from http://www.weather.com/services/xmloap.html
+ //
+ $this->LastUpdated=$this->in("","",$data);
+ $dnaminfo = $this->in("","",$data);
+ $sep = strpos($dnaminfo, ',');
+ if($sep != false) {
+ $this->city = substr($dnaminfo, 0, $sep);
+ $this->country = substr($dnaminfo, $sep + 1, strlen($dnaminfo) - $sep - 1);
+ }
+ $cc = $this->in("","",$data);
+ $this->Temperature=$this->in("","",$cc);
+ $this->Real=$this->in("","",$cc);
+ $barinfo = $this->in("","",$cc);
+ $this->BarometricPressure=$this->in("","",$barinfo);
+ $windinfo = $this->in("","",$cc);
+ $this->WindSpeed = $this->in("","",$windinfo);
+ $this->WindDirection = $this->in("","",$windinfo);
+ $this->Humidity = $this->in("","",$cc);
+ $this->Visibility = $this->in("","",$cc);
+ $uvinfo = $this->in("","",$cc);
+ $this->UV = $this->in("","",$uvinfo);
+ $this->CIcon = $this->in("","", $cc);
+ $this->ConditionText = $this->in("","",$cc);
+ $this->Forecast = $this->readForecast($data);
//Are we using metric or imperial system
if ($this->use_metric == 'YES') {
$this->Temperature = round((5/9) * ($this->Temperature - 32));
$this->Real = round((5/9) * ($this->Real - 32));
$this->BarometricPressure = round($this->BarometricPressure * 2.54);
- $this->Visibility = round($this->Visibility * 1.609344);
+ if (strpos($this->Visibility, 'Unlimited') != false) {
+ $this->Visibility = round($this->Visibility * 1.609344);
+ }
+
$this->WindSpeed = round($this->WindSpeed * 1.609344);
}
- if (strlen($this->ConText) > 0) {
- $this->ConditionText = $this->ConText;
- foreach ($Weather_Types as $pair) {
- if ($pair[1] != $this->ConditionText)
- continue;
- $this->ConditionImage = $pair[0];
- break;
- }
- if(strlen($this->ConditionImage) == 0)
- list($this->ConditionImage, $blah) = $Weather_Types[$this->CIcon];
- }
- else {
- list($this->ConditionImage, $this->ConditionText) = $Weather_Types[$this->CIcon];
- }
- $this->ConditionImage = (strlen($this->ConditionImage) > 0) ? $this->ConditionImage : 'unknown.png';
+ // if (strlen($this->ConText) > 0) {
+ // $this->ConditionText = $this->ConText;
+ // foreach ($Weather_Types as $pair) {
+ // if ($pair[1] != $this->ConditionText)
+ // continue;
+ // $this->ConditionImage = $pair[0];
+ // break;
+ // }
+ // if(strlen($this->ConditionImage) == 0)
+ // list($this->ConditionImage, $blah) = $Weather_Types[$this->CIcon];
+ // }
+ // else {
+ // list($this->ConditionImage, $this->ConditionText) = $Weather_Types[$this->CIcon];
+ // }
+ // $this->ConditionImage = (strlen($this->ConditionImage) > 0) ? $this->ConditionImage : 'unknown.png';
+ $this->ConditionImage = $this->CIcon.".png";
}
function getRadarURL() {
- @$data = file('http://www.weather.com/weather/map/' . $this->acid . '?from=LAPmaps&setcookie=1');
+ @$data = file('http://www.weather.com/weather/map/' . $this->acid . '?from=LAPmaps&setcookie=1');
if (is_array($data) && count($data)) {
foreach($data as $line) {
if(substr(trim($line), 0, 29) != 'if (isMinNS4) var mapNURL = "') continue;
$url1 = substr(trim($line), 30);
- $url1 = 'http://www.weather.com/' . substr($url1, 0, strlen($url1) - 2);
+ $url1 = 'http://www.weather.com/' . substr($url1, 0, strlen($url1) - 2);
break;
}
@@ -142,29 +160,43 @@
}
function readForecast($data) {
- global $Weather_Types;
$ret = array();
- $data = explode('|', $data);
for($i = 0;$i<5;$i++) {
- // mktime uses 0-6; msnbc gives us 1-7; adjust msnbc to match mktime
- $dayofweek = $data[$i] - 1;
- $forecast = new Forecast($data[5 + $i],$dayofweek);
- $forecast->dayofweek = $dayofweek;
- list($forecast->DescImage,$forecast->DescText) = $Weather_Types[$data[15 + $i]];
- $forecast->DescImage = (strlen($forecast->DescImage) > 0) ? $forecast->DescImage : 'unknown.png';
- $forecast->DescText = (strlen($forecast->DescText) > 0) ? $forecast->DescText : t('Unknown') . ' (' . $data[15+$i] . ')';
- if($this->use_metric == 'YES') {
- $forecast->HighTemperature = round((5/9) * ($data[20 + $i] - 32));
- $forecast->LowTemperature = round((5/9) * ($data[40 + $i] -32 ));
- } else {
- $forecast->HighTemperature = $data[20 + $i];
- $forecast->LowTemperature = $data[40 + $i];
+ $data1 = $this->in("",$data);
+ $day = $this->in("LastUpdated, $i);
+ switch ($day) {
+ case 'Sunday': $forecast->dayofweek = 0; break;
+ case 'Monday': $forecast->dayofweek = 1; break;
+ case 'Tuesday': $forecast->dayofweek = 2; break;
+ case 'Wednesday': $forecast->dayofweek = 3; break;
+ case 'Thursday': $forecast->dayofweek = 4; break;
+ case 'Friday': $forecast->dayofweek = 5; break;
+ case 'Saturday': $forecast->dayofweek = 6; break;
}
+ // $forecast->dayofweek = $i;
+
+ $fc = $this->in("","",$data1);
+ $forecast->DescText = $this->in("","",$fc);
+ $icon = $this->in("","",$fc);
+ $forecast->DescImage = $icon.".png";
+
+ $forecast->HighTemperature = $this->in("","",$data1);
+ $forecast->LowTemperature = $this->in("","",$data1);
+
+ if($this->use_metric == 'YES') {
+ if ($forecast->HighTemperature != 'N/A') {
+ $forecast->HighTemperature = round((5/9) * ($forecast->HighTemperature - 32));
+ }
+ if ($forecast->LowTemperature != 'N/A') {
+ $forecast->LowTemperature = round((5/9) * ($forecast->LowTemperature -32 ));
+ }
+ }
$ret[$i] = $forecast;
}
return $ret;
}
-}
\ Pas de fin de ligne à la fin du fichier.
+}
diff -Naur weather.svn/tmpl/default/weather.php weather/tmpl/default/weather.php
--- weather.svn/tmpl/default/weather.php 2007-08-05 12:17:51.000000000 +0200
+++ weather/tmpl/default/weather.php 2007-08-05 12:00:24.000000000 +0200
@@ -75,6 +75,7 @@
?>)
+
@@ -145,9 +146,17 @@
-
- : LastUpdated ?>
-
+
+
+
+
+ |
+
+
+ : LastUpdated ?>
+ |
+
+