Changeset 355e31d31 in mythtv


Ignore:
Timestamp:
Jun 24, 2013, 10:22:49 PM (11 years ago)
Author:
Joe Ripley <jripley@…>
Branches:
fixes/0.26
Children:
f5c2875ec
Parents:
fe3e4d09d
git-author:
Joe Ripley <jripley@…> (06/24/13 22:22:49)
git-committer:
Stuart Morgan <smorgan@…> (06/24/13 22:27:51)
Message:

MythWeather? Environment Canada Parser update

Fixes #11623

Signed-off-by: Stuart Morgan <smorgan@…>
(cherry picked from commit 34620185a9a5b832bcc9bb597e3afe0668fbee06)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mythplugins/mythweather/mythweather/scripts/ca_envcan/ENVCANParser.pm

    rfe3e4d09d r355e31d31  
    1212use XML::Simple;
    1313
    14 our $VERSION = 0.5;
     14our $VERSION = 0.6;
    1515
    1616my %results;
     
    2323                    SE => "Southeast",  WNW => "West Northwest",
    2424                    SW => "Southwest",  NNW => "North Northwest");
     25
     26my %degrees = (     N  => 0,   NNE => 22.5,
     27                    S  => 180, ENE => 67.5,
     28                    E  => 90,  ESE => 112.5,
     29                    W  => 270, SSE => 157.5,
     30                    NE => 45,  SSW => 202.5,
     31                    NW => 315, WSW => 247.5,
     32                    SE => 135, WNW => 292.5,
     33                    SW => 225, NNW => 337.5);
    2534
    2635sub getIcon {
     
    3645        $icon = 'fog.png';
    3746    }
     47    elsif ($condition =~ /precip/i) {
     48        $icon = 'lshowers.png';
     49        $icon = 'rainsnow.png'  if ($condition =~ /freezing/i);
     50    }
    3851    elsif ($condition =~ /drizzle/i) {
    3952        $icon = 'lshowers.png';
     
    4861        $icon = 'thunshowers.png' if ($condition =~ /thunder/i);
    4962    }
     63    elsif ($condition =~ /overcast/i) {
     64        $icon = 'cloudy.png';
     65    }
    5066    elsif ($condition =~ /cloud/i) {
    5167        $icon = 'cloudy.png';
     
    5874    elsif ($condition =~ /clear/i) {
    5975        $icon = 'fair.png';
     76        $icon = 'pcloudy.png' if ($condition =~ /clearing/i);
    6077    }
    6178    elsif ($condition =~ /sun/i) {
     
    7693    foreach my $type (@types) { $results{$type} = ""; }
    7794
    78     my $xml = XMLin($data);
     95    my $xml = XMLin($data, ForceArray => [ 'id' ] );
    7996    die if (!$xml);
    8097
    81     $results{'copyright'}  = $xml->{channel}->{copyright};
    82     if ($xml->{channel}->{title} =~ /^(.*) - Weather/) {
     98    $results{'copyright'}  = $xml->{rights};
     99    if ($xml->{title} =~ /^(.*) - Weather/) {
    83100        $results{'cclocation'} = ucfirst($1);
    84101        $results{'3dlocation'} = ucfirst($1);
     
    87104   
    88105    my $i = 0;
    89     foreach my $item (@{$xml->{channel}->{item}}) {
     106
     107    foreach my $item (@{$xml->{entry}}) {
    90108        if ($item->{title} =~ /Current Conditions/) {
    91             if ($item->{description} =~ /Condition:\<\/b\>\s*([\w ]*)\s*\<br\/\>/s) {
     109            if ($item->{summary}->{content} =~ /Condition:\<\/b\>\s*([\w ]*)\s*\<br\/\>/s) {
    92110                $results{'weather'} = $1;
    93111                $results{'weather_icon'} = getIcon($1);
    94112            }
    95113            $results{'temp'}     = sprintf("%.0f", $1)
    96                 if ($item->{description} =~ /Temperature:\<\/b\>\s*(-?\d*\.?\d*)\&deg\;\C\s*\<br\/\>/s);
     114                if ($item->{summary}->{content} =~ /Temperature:\<\/b\>\s*(-?\d*\.?\d*)\&deg\;\C\s*\<br\/\>/s);
    97115            $results{'pressure'} = sprintf("%d", $1 * 10)
    98                 if ($item->{description} =~ /Pressure \/ Tendency:\<\/b\>\s*(\d*\.?\d*) kPa\s*.*\<br\/\>/s);
     116                if ($item->{summary}->{content} =~ /Pressure.*:\<\/b\>\s*(\d*\.?\d*) kPa\s*.*\<br\/\>/s);
    99117            $results{'visibility'} = sprintf("%.1f", $1)
    100                 if ($item->{description} =~ /Visibility:\<\/b\>\s*(\d*\.?\d*) km\s*.*\<br\/\>/s);
     118                if ($item->{summary}->{content} =~ /Visibility:\<\/b\>\s*(\d*\.?\d*) km\s*.*\<br\/\>/s);
    101119            $results{'relative_humidity'} = $1
    102                 if ($item->{description} =~ /Humidity:\<\/b\>\s*(\d*) \%\<br\/\>/s);
    103             if ($item->{description} =~ /Wind Chill:\<\/b\>\s*(-?\d*\.?\d*)\s*\<br\/\>/s) {
     120                if ($item->{summary}->{content} =~ /Humidity:\<\/b\>\s*(\d*) \%\<br\/\>/s);
     121            if ($item->{summary}->{content} =~ /Wind Chill:\<\/b\>\s*(-?\d*\.?\d*)\s*\<br\/\>/s) {
    104122                $results{'appt'} = $1;
    105123                $results{'windchill'} = $1;
    106124            }
    107125            $results{'dewpoint'} = sprintf("%.0f", $1)
    108                 if ($item->{description} =~ /Dewpoint:\<\/b\>\s*(-?\d*\.?\d*)\&deg\;\C\s*\<br\/\>/s);
    109             if ($item->{description} =~ /(\d*\:\d*[\w ]*\d*[\w *]\d*)\s*\<br\/\>/s) {
     126                if ($item->{summary}->{content} =~ /Dewpoint:\<\/b\>\s*(-?\d*\.?\d*)\&deg\;\C\s*\<br\/\>/s);
     127            if ($item->{summary}->{content} =~ /(\d*\:\d*[\w ]*\d*[\w *]\d*)\s*\<br\/\>/s) {
    110128                $results{'observation_time'} = "Last updated at ". $1;
    111129                $results{'updatetime'} = "Last updated at ". $1;
    112130            }
    113             if ($item->{description} =~ /Wind:\<\/b\>(.*)\<br\/\>/s) {
     131            if ($item->{summary}->{content} =~ /Wind:\<\/b\>(.*)\<br\/\>/s) {
    114132                my $wind = $1;
    115133                if ($wind =~ /\s*(\d*)\s*km\/h\s*/i) {
     
    119137                }
    120138                if ($wind =~ /\s*(\w*)\s*(\d*)\s*km\/h\s*/i) {
    121                     $results{'wind_dir'}   = $directions{$1};
     139                    $results{'wind_dir'}     = $directions{$1};
     140                    $results{'wind_degrees'} = $degrees{$1};
    122141                    $results{'wind_speed'} = $2;
    123142                }
Note: See TracChangeset for help on using the changeset viewer.