diff --git mythplugins/mythweather/mythweather/scripts/ca_envcan/ENVCANParser.pm mythplugins/mythweather/mythweather/scripts/ca_envcan/ENVCANParser.pm
index 7420a66..66677da 100644
|
|
use strict; |
11 | 11 | use POSIX; |
12 | 12 | use XML::Simple; |
13 | 13 | |
14 | | our $VERSION = 0.5; |
| 14 | our $VERSION = 0.6; |
15 | 15 | |
16 | 16 | my %results; |
17 | 17 | my %directions = ( N => "North", NNE => "North Northeast", |
… |
… |
my %directions = ( N => "North", NNE => "North Northeast", |
23 | 23 | SE => "Southeast", WNW => "West Northwest", |
24 | 24 | SW => "Southwest", NNW => "North Northwest"); |
25 | 25 | |
| 26 | my %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); |
| 34 | |
26 | 35 | sub getIcon { |
27 | 36 | my $condition = shift; |
28 | 37 | my $icon; |
… |
… |
sub getIcon { |
35 | 44 | elsif ($condition =~ /fog/i) { |
36 | 45 | $icon = 'fog.png'; |
37 | 46 | } |
| 47 | elsif ($condition =~ /precip/i) { |
| 48 | $icon = 'lshowers.png'; |
| 49 | $icon = 'rainsnow.png' if ($condition =~ /freezing/i); |
| 50 | } |
38 | 51 | elsif ($condition =~ /drizzle/i) { |
39 | 52 | $icon = 'lshowers.png'; |
40 | 53 | $icon = 'rainsnow.png' if ($condition =~ /freezing/i); |
… |
… |
sub getIcon { |
47 | 60 | ($condition =~ /flurries/i)); |
48 | 61 | $icon = 'thunshowers.png' if ($condition =~ /thunder/i); |
49 | 62 | } |
| 63 | elsif ($condition =~ /overcast/i) { |
| 64 | $icon = 'cloudy.png'; |
| 65 | } |
50 | 66 | elsif ($condition =~ /cloud/i) { |
51 | 67 | $icon = 'cloudy.png'; |
52 | 68 | $icon = 'mcloudy.png' if ($condition =~ /mostly/i); |
… |
… |
sub getIcon { |
57 | 73 | } |
58 | 74 | elsif ($condition =~ /clear/i) { |
59 | 75 | $icon = 'fair.png'; |
| 76 | $icon = 'pcloudy.png' if ($condition =~ /clearing/i); |
60 | 77 | } |
61 | 78 | elsif ($condition =~ /sun/i) { |
62 | 79 | $icon = 'sunny.png'; |
… |
… |
sub doParse { |
75 | 92 | # Initialize results hash |
76 | 93 | foreach my $type (@types) { $results{$type} = ""; } |
77 | 94 | |
78 | | my $xml = XMLin($data); |
| 95 | my $xml = XMLin($data, ForceArray => [ 'id' ] ); |
79 | 96 | die if (!$xml); |
80 | 97 | |
81 | | $results{'copyright'} = $xml->{channel}->{copyright}; |
82 | | if ($xml->{channel}->{title} =~ /^(.*) - Weather/) { |
| 98 | $results{'copyright'} = $xml->{rights}; |
| 99 | if ($xml->{title} =~ /^(.*) - Weather/) { |
83 | 100 | $results{'cclocation'} = ucfirst($1); |
84 | 101 | $results{'3dlocation'} = ucfirst($1); |
85 | 102 | $results{'6dlocation'} = ucfirst($1); |
86 | 103 | } |
87 | 104 | |
88 | 105 | my $i = 0; |
89 | | foreach my $item (@{$xml->{channel}->{item}}) { |
| 106 | |
| 107 | foreach my $item (@{$xml->{entry}}) { |
90 | 108 | 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) { |
92 | 110 | $results{'weather'} = $1; |
93 | 111 | $results{'weather_icon'} = getIcon($1); |
94 | 112 | } |
95 | 113 | $results{'temp'} = sprintf("%.0f", $1) |
96 | | if ($item->{description} =~ /Temperature:\<\/b\>\s*(-?\d*\.?\d*)\°\;\C\s*\<br\/\>/s); |
| 114 | if ($item->{summary}->{content} =~ /Temperature:\<\/b\>\s*(-?\d*\.?\d*)\°\;\C\s*\<br\/\>/s); |
97 | 115 | $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); |
99 | 117 | $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); |
101 | 119 | $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) { |
104 | 122 | $results{'appt'} = $1; |
105 | 123 | $results{'windchill'} = $1; |
106 | 124 | } |
107 | 125 | $results{'dewpoint'} = sprintf("%.0f", $1) |
108 | | if ($item->{description} =~ /Dewpoint:\<\/b\>\s*(-?\d*\.?\d*)\°\;\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*)\°\;\C\s*\<br\/\>/s); |
| 127 | if ($item->{summary}->{content} =~ /(\d*\:\d*[\w ]*\d*[\w *]\d*)\s*\<br\/\>/s) { |
110 | 128 | $results{'observation_time'} = "Last updated at ". $1; |
111 | 129 | $results{'updatetime'} = "Last updated at ". $1; |
112 | 130 | } |
113 | | if ($item->{description} =~ /Wind:\<\/b\>(.*)\<br\/\>/s) { |
| 131 | if ($item->{summary}->{content} =~ /Wind:\<\/b\>(.*)\<br\/\>/s) { |
114 | 132 | my $wind = $1; |
115 | 133 | if ($wind =~ /\s*(\d*)\s*km\/h\s*/i) { |
116 | 134 | $results{'wind_dir'} = 'Calm'; |
… |
… |
sub doParse { |
118 | 136 | $results{'wind_gust'} = 0; |
119 | 137 | } |
120 | 138 | 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}; |
122 | 141 | $results{'wind_speed'} = $2; |
123 | 142 | } |
124 | 143 | if ($wind =~ /\s*(\w*)\s*(\d*)\s*km\/h\s*gust\s*(\d*)\s*km\/h/i) { |