Ticket #3303: weather.3.patch

File weather.3.patch, 10.5 KB (added by maverik044, 17 years ago)

Patch updated to correct typo

  • weather/includes/objects/Forecast.php

    diff -rup /home/mythtv/mythtv/myth_src/13238/mythplugins/mythweb/modules/weather/includes/objects/Forecast.php ./weather/includes/objects/Forecast.php
    old new class Forecast { 
    2424    var $HighTemperature;
    2525    var $LowTemperature;
    2626
    27     function Forecast($date, $real_dayofweek) {
     27    function Forecast($date,$d) {
     28        $i = strpos($date, "/");
     29        $j = strpos($date, "/", $i+1);
     30        $month = substr($date,0,$i);
     31        $day   = substr($date,$i+1,$j-$i-1);
     32        $year  = substr($date,$j+1,2);
    2833
    29         $month = substr($date,0,2);
    30         $day   = substr($date,3,2);
    31         $year  = substr($date,6,4);
    32 
    33         $temp_date         = mktime(0,0,0,$month,$day,$year);
    34         $date_time_array   = getdate( $temp_date );
    35         $claimed_dayofweek = $date_time_array['wday'];
    36 
    37         if ($real_dayofweek != $claimed_dayofweek)
    38             $this->date = date('m/d/Y', mktime(0, 0, 0, $month  , $day+1, $year));
    39         else
    40             $this->date = $date;
     34        $this->date = date('m/d/Y', mktime(0,0,0,$month,$day+$d,$year));
    4135    }
    4236}
  • weather/includes/objects/WeatherSite.php

    diff -rup /home/mythtv/mythtv/myth_src/13238/mythplugins/mythweb/modules/weather/includes/objects/WeatherSite.php ./weather/includes/objects/WeatherSite.php
    old new class WeatherSite { 
    5151        $this->RadarImage = $this->getRadarURL();
    5252    }
    5353
     54    function in($One,$Two,$data) {
     55        $x = strpos($data,$One) + strlen($One);
     56
     57        if($x == false) {
     58           return "N/A";
     59        }
     60
     61        $y = strpos($data,$Two,$x);
     62
     63        if($y == false) {
     64           return "N/A";
     65        }
     66
     67        $str = substr($data, $x, $y - $x);
     68          return $str;
     69    }
     70
    5471    function getData() {
    5572        global $Weather_Types;
    56         $data = file('http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=' . $this->acid);
     73        $data=join('',file("http://xoap.weather.com/weather/local/".$this->acid."?cc=*&unit=F&dayf=5"));
    5774
    58         foreach($data as $line) {
    59             if(strpos($line, 'this.sw') === false)
    60                 continue;
    61             if(strpos($line, 'swTempCel') !== false)
    62                 continue;
    63 
    64             $line = trim($line);
    65             list($name, $value) = explode(' = "', $line);
    66             $name  = substr($name, 7);
    67             $value = substr($value, 0, strlen($value) - 2);
    68 
    69             switch ($name) {
    70                 case 'City':    $this->city               = $value;             break;
    71                 case 'SubDiv':  $this->subdiv             = $value;             break;
    72                 case 'Country': $this->country            = $value;             break;
    73                 case 'Region':  $this->region             = $value;             break;
    74                 case 'Temp':    $this->Temperature        = $value;             break;
    75                 case 'CIcon':   $this->CIcon              = $value;             break;
    76                 case 'WindS':   $this->WindSpeed          = $value;             break;
    77                 case 'WindD':   $this->WindDirection      = $value;             break;
    78                 case 'Baro':    $this->BarometricPressure = $value;             break;
    79                 case 'Humid':   $this->Humidity           = $value;             break;
    80                 case 'Real':    $this->Real               = $value;             break;
    81                 case 'UV':      $this->UV                 = $value;             break;
    82                 case 'Vis':     $this->Visibility         = $value;             break;
    83                 case 'LastUp':  $this->LastUpdated        = $value;             break;
    84                 case 'ConText': $this->ConText            = $value;             break;
    85                 case 'Fore':    $this->Forecast = $this->readForecast($value);  break;
    86                 default:        /* Weird, unknown type */                       break;
    87             }
    88         }
     75//
     76// Technically we should include the partner id and key
     77// if this stops working, change to the following:
     78// http://xoap.weather.com/weather/local/".$this->acid."?cc=*&unit=F&dayf=5&prod=xoap&par=1036905921&key=f68c2657a4fd3e2e"
     79// may need to get a new one from http://www.weather.com/services/xmloap.html
     80//
     81        $this->LastUpdated=$this->in("<lsup>","</lsup>",$data);
     82        $dnaminfo = $this->in("<dnam>","</dnam>",$data);
     83        $sep = strpos($dnaminfo, ',');
     84        if($sep != false) {
     85                $this->city = substr($dnaminfo, 0, $sep);
     86                $this->country = substr($dnaminfo, $sep + 1, strlen($dnaminfo) - $sep - 1);
     87        }
     88        $cc = $this->in("<cc>","</cc>",$data);
     89        $this->Temperature=$this->in("<tmp>","</tmp>",$cc);
     90        $this->Real=$this->in("<flik>","</flik>",$cc);
     91        $barinfo = $this->in("<bar>","</bar>",$cc);
     92        $this->BarometricPressure=$this->in("<r>","</r>",$barinfo);
     93        $windinfo = $this->in("<wind>","</wind>",$cc);
     94        $this->WindSpeed = $this->in("<s>","</s>",$windinfo);
     95        $this->WindDirection = $this->in("<t>","</t>",$windinfo);
     96        $this->Humidity = $this->in("<hmid>","</hmid>",$cc);
     97        $this->Visibility = $this->in("<vis>","</vis>",$cc);
     98        $uvinfo = $this->in("<uv>","</uv>",$cc);
     99        $this->UV = $this->in("<i>","</i>",$uvinfo);
     100        $this->CIcon = $this->in("<icon>","</icon>", $cc);
     101        $this->ConditionText = $this->in("<t>","</t>",$cc);
     102        $this->Forecast = $this->readForecast($data);
    89103
    90104    //Are we using metric or imperial system
    91105        if ($this->use_metric == 'YES') {
    92106            $this->Temperature        = round((5/9) * ($this->Temperature - 32));
    93107            $this->Real               = round((5/9) * ($this->Real - 32));
    94108            $this->BarometricPressure = round($this->BarometricPressure * 2.54);
    95             $this->Visibility         = round($this->Visibility * 1.609344);
     109            if (strpos($this->Visibility, 'Unlimited') != false) {
     110              $this->Visibility         = round($this->Visibility * 1.609344);
     111        }
    96112            $this->WindSpeed          = round($this->WindSpeed * 1.609344);
    97113        }
    98114
    99         if (strlen($this->ConText) > 0) {
    100             $this->ConditionText = $this->ConText;
    101             foreach ($Weather_Types as $pair) {
    102                 if ($pair[1] != $this->ConditionText)
    103                     continue;
    104                 $this->ConditionImage = $pair[0];
    105                 break;
    106             }
    107             if(strlen($this->ConditionImage) == 0)
    108                 list($this->ConditionImage, $blah) = $Weather_Types[$this->CIcon];
    109         }
    110         else {
    111             list($this->ConditionImage, $this->ConditionText) = $Weather_Types[$this->CIcon];
    112         }
    113         $this->ConditionImage = (strlen($this->ConditionImage) > 0) ? $this->ConditionImage : 'unknown.png';
     115     $this->ConditionImage = $this->CIcon.".png";
    114116    }
    115117
    116118    function getRadarURL() {
    class WeatherSite { 
    136138    }
    137139
    138140    function readForecast($data) {
    139         global $Weather_Types;
    140141        $ret = array();
    141142
    142         $data = explode('|', $data);
    143143        for($i = 0;$i<5;$i++) {
    144         // mktime uses 0-6;  msnbc gives us 1-7;  adjust msnbc to match mktime
    145             $dayofweek = $data[$i] - 1;
    146             $forecast = new Forecast($data[5 + $i],$dayofweek);
    147             $forecast->dayofweek = $dayofweek;
    148             list($forecast->DescImage,$forecast->DescText) = $Weather_Types[$data[15 + $i]];
    149             $forecast->DescImage = (strlen($forecast->DescImage) > 0) ? $forecast->DescImage : 'unknown.png';
    150             $forecast->DescText  = (strlen($forecast->DescText)  > 0) ? $forecast->DescText  : t('Unknown') . ' (' . $data[15+$i] . ')';
    151             if($this->use_metric == 'YES') {
    152                 $forecast->HighTemperature = round((5/9) * ($data[20 + $i] - 32));
    153                 $forecast->LowTemperature = round((5/9) * ($data[40 + $i] -32 ));
    154             } else {
    155             $forecast->HighTemperature = $data[20 + $i];
    156             $forecast->LowTemperature = $data[40 + $i];
     144            $data1 = $this->in("<day d=\"".$i,"</day>",$data);
     145            $day = $this->in("<day d=\"".$i."\" t=\"","\" dt",$data);
     146            $forecast = new Forecast($this->LastUpdated, $i);
     147            switch ($day) {
     148            case 'Sunday': $forecast->dayofweek = 0; break;
     149            case 'Monday': $forecast->dayofweek = 1; break;
     150            case 'Tuesday': $forecast->dayofweek = 2; break;
     151            case 'Wednesday': $forecast->dayofweek = 3; break;
     152            case 'Thursday': $forecast->dayofweek = 4; break;
     153            case 'Friday': $forecast->dayofweek = 5; break;
     154            case 'Saturday': $forecast->dayofweek = 6; break;
    157155            }
     156           // $forecast->dayofweek = $i;
     157           
     158            $fc = $this->in("<part p=\"d\">","</part>",$data1);
     159            $forecast->DescText = $this->in("<t>","</t>",$fc);
     160            $icon = $this->in("<icon>","</icon>",$fc);
     161            $forecast->DescImage = $icon.".png";
     162
     163            $forecast->HighTemperature = $this->in("<hi>","</hi>",$data1);
     164            $forecast->LowTemperature = $this->in("<low>","</low>",$data1);
     165
     166            if($this->use_metric == 'YES') {
     167              if ($forecast->HighTemperature != 'N/A') {
     168                $forecast->HighTemperature = round((5/9) * ($forecast->HighTemperature - 32));
     169              }
     170              if ($forecast->LowTemperature != 'N/A') {
     171                $forecast->LowTemperature = round((5/9) * ($forecast->LowTemperature -32 ));
     172              }
     173            }
    158174
    159175            $ret[$i] = $forecast;
    160176        }
    161177
    162178        return $ret;
    163179    }
    164 }
    165  No newline at end of file
     180}
  • weather/tmpl/default/weather.php

    diff -rup /home/mythtv/mythtv/myth_src/13238/mythplugins/mythweb/modules/weather/tmpl/default/weather.php ./weather/tmpl/default/weather.php
    old new  
    7575                ?>)</td>
    7676        </tr>
    7777        </table>
     78
    7879    </div>
    7980
    8081    <div class="forecast clearfix">
     
    146147    </div>
    147148
    148149    <p class="last_updated">
     150            <img src="<?php echo skin_url ?>img/weather/TWClogo_64px.png " class="alpha_png" />
     151       <?php echo "Weather data provided by weather.com" ?> </sup>
    149152        <?php echo t('Last Updated') ?>: <?php echo $site->LastUpdated ?>
    150153    </p>
    151154</div>