Ticket #4519: 4519_diff.5.patch
File 4519_diff.5.patch, 25.4 KB (added by , 16 years ago) |
---|
-
mythplugins/mythweather/mythweather/scripts/envcan.pl
24 24 my $email = 'vitaminjoe@gmail.com'; 25 25 my $updateTimeout = 15*60; 26 26 my $retrieveTimeout = 30; 27 my @types = ('cclocation', 'station_id', 28 29 30 31 32 33 34 35 36 37 38 27 my @types = ('cclocation', 'station_id', 'copyright', 28 'observation_time', 'observation_time_rfc822', 'weather', 29 'temp', 'relative_humidity', 30 'wind_dir', 'wind_degrees', 'wind_speed', 'wind_gust', 31 'pressure', 'dewpoint', 'heat_index', 'windchill', 32 'visibility', 'weather_icon', 'appt', 'wind_spdgst', 33 '3dlocation', '6dlocation', 'date-0', 'icon-0', 'low-0', 'high-0', 34 'date-1', 'icon-1', 'low-1', 'high-1', 35 'date-2', 'icon-2', 'low-2', 'high-2', 'updatetime', 36 'date-3', 'icon-3', 'low-3', 'high-3', 37 'date-4', 'icon-4', 'low-4', 'high-4', 38 'date-5', 'icon-5', 'low-5', 'high-5' ); 39 39 40 40 my $dir = "./"; 41 41 42 42 getopts('Tvtlu:d:'); 43 43 44 44 if (defined $opt_v) { 45 46 45 print "$name,$version,$author,$email\n"; 46 exit 0; 47 47 } 48 48 49 49 if (defined $opt_T) { 50 51 50 print "$updateTimeout,$retrieveTimeout\n"; 51 exit 0; 52 52 } 53 53 if (defined $opt_l) { 54 my $search = shift; 55 ENVCANLocation::AddStationIdSearch($search); 56 ENVCANLocation::AddRegionIdSearch($search); 57 ENVCANLocation::AddCitySearch($search); 58 ENVCANLocation::AddProvinceSearch($search); 59 my $results = doSearch(); 60 my $result; 61 while($result = shift @$results) { 62 if ($result->{station_id} ne "NA" ) { 63 print "$result->{station_id}::"; 64 print "$result->{city}, $result->{region_id}\n"; 65 } 66 } 67 68 exit 0; 69 54 my $search = shift; 55 ENVCANLocation::AddStationIdSearch($search); 56 ENVCANLocation::AddRegionIdSearch($search); 57 ENVCANLocation::AddCitySearch($search); 58 ENVCANLocation::AddProvinceSearch($search); 59 my $results = doSearch(); 60 my $result; 61 while($result = shift @$results) { 62 if ($result->{station_id} ne "NA" ) { 63 print "$result->{station_id}::"; 64 print "$result->{city}, $result->{region_id}\n"; 65 } 66 } 67 exit 0; 70 68 } 71 69 72 70 73 71 if (defined $opt_t) { 74 75 72 foreach (@types) {print; print "\n";} 73 exit 0; 76 74 } 77 75 78 76 if (defined $opt_d) { 79 77 $dir = $opt_d; 80 78 } 81 79 82 80 # check variables for defined status … … 106 104 107 105 # no cache, grab from the web 108 106 if ($getData) { 109 my $base_url = 'http://www.weatheroffice.gc.ca/ forecast/city_e.html?';110 my $response = get $base_url . $loc ;107 my $base_url = 'http://www.weatheroffice.gc.ca/rss/city/'; 108 my $response = get $base_url . $loc .'_e.xml'; 111 109 die unless defined $response; 112 110 113 111 %results = ENVCANParser::doParse($response, @types); … … 129 127 130 128 # do some quick conversions 131 129 if ($units eq "ENG") { 132 133 134 135 136 137 138 139 140 $results{'wind_spdgst'} = sprintf("%.2f (%.2f) mph", $results{'wind_speed'}, $results{'wind_gust'});141 142 143 if ($results{"high-$i"} ne "NA") {144 130 $results{'temp'} = int(((9/5) * $results{'temp'}) + 32); 131 $results{'dewpoint'} = int(((9/5) * $results{'dewpoint'}) + 32); 132 $results{'windchill'} = int(((9/5) * $results{'windchill'}) + 32); 133 $results{'appt'} = int(((9/5) * $results{'appt'}) + 32); 134 $results{'visibility'} = sprintf("%.1f", ($results{'visibility'} * 0.621371192)); 135 $results{'pressure'} = sprintf("%.2f", $results{'pressure'} * 0.0295301); 136 $results{'wind_gust'} = sprintf("%.2f", $results{'wind_gust'} * 0.621371192); 137 $results{'wind_speed'} = sprintf("%.2f", $results{'wind_speed'} * 0.621371192); 138 $results{'wind_spdgst'} = sprintf("%.2f (%.2f)", $results{'wind_speed'}, $results{'wind_gust'}); 139 140 for (my $i=0;$i<6;$i++) { 141 if ($results{"high-$i"} =~ /\d*/) { 142 $results{"high-$i"} = int(((9/5) * $results{"high-$i"}) + 32); 145 143 } 146 if ($results{"low-$i"} ne "NA") {147 144 if ($results{"low-$i"} =~ /\d*/) { 145 $results{"low-$i"} = int(((9/5) * $results{"low-$i"}) + 32); 148 146 } 149 147 } 150 148 } else { 151 149 $results{'wind_spdgst'} = sprintf("%.2f (%.2f)", $results{'wind_speed'}, $results{'wind_gust'}); 152 150 } 153 151 154 152 155 153 foreach my $key (sort (keys %results)) { 156 157 158 159 160 161 154 print "$key". "::"; 155 if (length($results{$key}) == 0) { 156 print "NA\n"; 157 } else { 158 print $results{$key} ."\n"; 159 } 162 160 } 163 161 -
mythplugins/mythweather/mythweather/scripts/envcan_animaps.pl
37 37 exit 0; 38 38 } 39 39 if (defined $opt_l) { 40 40 my $search = shift; 41 41 ENVCANMapSearch::AddSatSearch($search); 42 42 ENVCANMapSearch::AddSatClassSearch($search); 43 43 ENVCANMapSearch::AddImageTypeSearch($search); … … 79 79 80 80 # Get list of images (at most 10) 81 81 foreach my $line (split(/\n/, $response)) { 82 83 84 85 82 if ($line =~ /theImagesComplete\[\d*\] \= \"(.*)\"\;/) { 83 push (@image_list, $1); 84 if ($#image_list >= 10) { shift @image_list; } 85 } 86 86 } 87 87 88 88 # Download map files, if necessary (maps are stale after 15 minutes) … … 95 95 } 96 96 97 97 getstore($base_url . $image, $path . $i); 98 98 $i++; 99 99 } 100 100 101 101 # Determine image size 102 102 if (!$size) { 103 104 105 103 use Image::Size; 104 my ($x, $y) = imgsize("${path}0"); 105 $size = "${x}x$y" if ($x && $y); 106 106 } 107 107 108 108 print "amdesc::$desc\n"; -
mythplugins/mythweather/mythweather/scripts/ENVCANParser.pm
1 # This script parses the HTML of an Environment Canada weather forecast1 # This script parses the XML of an Environment Canada weather forecast 2 2 # page as returned from http://www.weatheroffice.gc.ca. 3 3 # 4 # TODO Environment Canada only reports 5 day forecasts. 5 # 6 day forecastlayout is used to report 5 day information.4 # TODO Environment Canada only reports 5 day forecasts. 6 day forecast 5 # layout is used to report 5 day information. 6 6 # 7 # TODO Code is pretty messy right now, by no means an elegant solution 8 # 9 # This requires the HTML::Parser module. 7 # This requires the XML::Simple module. 10 8 11 9 package ENVCANParser; 12 10 use strict; 13 11 use POSIX; 14 use HTML::Parser ();12 use XML::Simple; 15 13 16 our $VERSION = 0. 1;14 our $VERSION = 0.2; 17 15 18 16 my %results; 19 my %inside; 20 my $scratch; 21 my %directions = ( N => "North", S => "South", E => "East", W => "West", 22 NE => "Northeast", NW => "Northwest", 23 SE => "Southeast", SW => "Southwest"); 17 my %directions = ( N => "North", NNE => "North Northeast", 18 S => "South", ENE => "East Northeast", 19 E => "East", ESE => "East Southeast", 20 W => "West", SSE => "South Southeast", 21 NE => "Northeast", SSW => "South Southwest", 22 NW => "Northwest", WSW => "West Southwest", 23 SE => "Southeast", WNW => "West Northwest", 24 SW => "Southwest", NNW => "North Northwest"); 24 25 25 sub start_h{26 my ($tag, %attr) = @_;27 $inside{$tag} = 1;26 sub getIcon { 27 my $condition = shift; 28 my $icon; 28 29 29 # Copy attributes 30 $inside{"$tag-id"} = $attr{id} if defined $attr{id}; 31 $inside{"$tag-class"} = $attr{class} if defined $attr{class}; 32 $inside{"$tag-src"} = $attr{src} if defined $attr{src}; 33 $inside{"$tag-longdesc"} = $attr{longdesc} if defined $attr{longdesc}; 34 35 doIMG() if $inside{img}; 36 } 37 38 # End tag, clear hash 39 sub end_h { 40 my ($tag) = @_; 41 undef $inside{$tag}; 42 undef $inside{"$tag-id"}; 43 undef $inside{"$tag-class"}; 44 } 45 46 sub text { 47 48 if (defined($inside{'title'}) && $inside{'title'}) { 49 $_[0] =~ s/\n//sg; 50 $_[0] =~ /(.*),\s*(.*)- 5 Day Weather/; 51 $results{'cclocation'} = "$1, $2"; 52 $results{'3dlocation'} = "$1, $2"; 53 $results{'6dlocation'} = "$1, $2"; 30 if ( ($condition =~ /snow/i) || ($condition =~ /flurries/i)) { 31 $icon = 'flurries.png'; 32 $icon = 'rainsnow.png' if ($condition =~ /rain/i); 33 $icon = 'snowshow.png' if ($condition =~ /heavy/i); 54 34 } 55 56 if (defined($inside{'h3'}) && $inside{'h3'}) { 57 if ($inside{'div-id'} eq "f1") { $results{'date-0'} = $_[0]; } 58 if ($inside{'div-id'} eq "f2") { $results{'date-1'} = $_[0]; } 59 if ($inside{'div-id'} eq "f3") { $results{'date-2'} = $_[0]; } 60 if ($inside{'div-id'} eq "f4") { $results{'date-3'} = $_[0]; } 61 if ($inside{'div-id'} eq "f5") { $results{'date-4'} = $_[0]; } 62 if ($inside{'div-id'} eq "f6") { $results{'date-5'} = $_[0]; } 35 elsif ($condition =~ /fog/i) { 36 $icon = 'fog.png'; 63 37 } 64 65 if ($inside{li}) { 66 if (defined($inside{'li-class'})) { 67 if ($inside{'li-class'} eq "low") { 68 if ($inside{'div-id'} eq "f1") { 69 $_[0] =~ /\w* (-?\d*)/; $results{'low-0'} = $1; } 70 if ($inside{'div-id'} eq "f2") { 71 $_[0] =~ /\w* (-?\d*)/; $results{'low-1'} = $1; } 72 if ($inside{'div-id'} eq "f3") { 73 $_[0] =~ /\w* (-?\d*)/; $results{'low-2'} = $1; } 74 if ($inside{'div-id'} eq "f4") { 75 $_[0] =~ /\w* (-?\d*)/; $results{'low-3'} = $1; } 76 if ($inside{'div-id'} eq "f5") { 77 $_[0] =~ /\w* (-?\d*)/; $results{'low-4'} = $1; } 78 if ($inside{'div-id'} eq "f6") { 79 $_[0] =~ /\w* (-?\d*)/; $results{'low-5'} = $1; } 80 } 81 82 if ($inside{'li-class'} eq "high") { 83 if ($inside{'div-id'} eq "f1") { 84 $_[0] =~ /\w* (-?\d*)/; $results{'high-0'} = $1; } 85 if ($inside{'div-id'} eq "f2") { 86 $_[0] =~ /\w* (-?\d*)/; $results{'high-1'} = $1; } 87 if ($inside{'div-id'} eq "f3") { 88 $_[0] =~ /\w* (-?\d*)/; $results{'high-2'} = $1; } 89 if ($inside{'div-id'} eq "f4") { 90 $_[0] =~ /\w* (-?\d*)/; $results{'high-3'} = $1; } 91 if ($inside{'div-id'} eq "f5") { 92 $_[0] =~ /\w* (-?\d*)/; $results{'high-4'} = $1; } 93 if ($inside{'div-id'} eq "f6") { 94 $_[0] =~ /\w* (-?\d*)/; $results{'high-5'} = $1; } 95 } 96 } 38 elsif ( ($condition =~ /rain/i) || ($condition =~ /showers/i) ) { 39 $icon = 'showers.png'; 40 $icon = 'lshowers.png' if ( ($condition =~ /chance/i) || 41 ($condition =~ /few/i)); 42 $icon = 'rainsnow.png' if ( ($condition =~ /snow/i) || 43 ($condition =~ /flurries/i)); 44 $icon = 'thunshowers.png' if ($condition =~ /thunder/i); 97 45 } 98 99 if (defined($inside{'div'}) && $inside{'div'}) { 100 if (defined($inside{'div-class'}) 101 && ($inside{'div-class'} eq "citycondition")) { 102 $results{'weather'} = $_[0]; 103 } 104 105 if (defined($inside{'div-id'}) 106 && ($inside{'div-id'} eq "cityobserved")) { 107 $_[0] =~ /.* (\d*\:\d*.*)/; 108 $results{'observation_time'} = "Last updated at $1"; 109 $results{'updatetime'} = "Last updated at $1"; 110 $results{'observation_time_rfc822'} = rfc822($1); 111 } 46 elsif ($condition =~ /cloud/i) { 47 $icon = 'cloudy.png'; 48 $icon = 'mcloudy.png' if ($condition =~ /mostly/i); 49 $icon = 'pcloudy.png' if ( ($condition =~ /few/i) || 50 ($condition =~ /mix/i) || 51 ($condition =~ /partly/i) || 52 ($condition =~ /period/i) ); 112 53 } 113 114 if (defined($inside{'dt'}) && $inside{'dt'}) { 115 if ($_[0] =~ /(Temperature)/) { $scratch = 1; return; } 116 if ($_[0] =~ /(Pressure)\/ Tendency/) { $scratch = 2; return; } 117 if ($_[0] =~ /(Visibility)/) { $scratch = 3; return; } 118 if ($_[0] =~ /(Humidity)/) { $scratch = 4; return; } 119 if ($_[0] =~ /(Dewpoint)/) { $scratch = 5; return; } 120 if ($_[0] =~ /(Wind Chill)/ ) { $scratch = 6; return; } 121 if ($_[0] =~ /(Wind)/) { $scratch = 7; return; } 54 elsif ($condition =~ /clear/i) { 55 $icon = 'fair.png'; 122 56 } 123 124 if (defined($inside{'dd'}) && $inside{'dd'}) { 125 if ($scratch == 1) { 126 $_[0] =~ /(-?\d*).*/; $results{'temp'} = $1; } 127 if ($scratch == 2) { 128 $_[0] =~ /(\d*\.\d+) kPa.*/; $results{'pressure'} = $1 * 10; } 129 if ($scratch == 3) { 130 $_[0] =~ /(\d*) km/; $results{'visibility'} = $1; } 131 if ($scratch == 4) { 132 $_[0] =~ /(\d*) \%/; $results{'relative_humidity'} = $1; } 133 if ($scratch == 5) { 134 $_[0] =~ /(-?\d*).*/; $results{'dewpoint'} = $1; } 135 if ($scratch == 6) { 136 $_[0] =~ /(-?\d*).*/; 137 $results{'appt'} = $1; 138 $results{'windchill'} = $1; 139 } 140 if ($scratch == 7) { 141 $_[0] =~ /.?(\w+) (\d+) km\/h/; 142 $results{'wind_dir'} = $directions{$1}; 143 $results{'wind_speed'} = $2; 144 145 if ($_[0] =~ /gust (\d+) km\/h/m) { 146 $results{'wind_gust'} = $1; 147 } else { 148 $results{'wind_gust'} = 0; 149 } 150 } 151 152 $scratch = 0; 57 elsif ($condition =~ /sun/i) { 58 $icon = 'sunny.png'; 153 59 } 154 155 } 156 157 sub doIMG { 158 my $icon; 159 160 # Get Icon 161 if (defined($inside{'img-src'}) 162 && ($inside{'img-src'} =~ /\/weathericons\/(\d*\.gif)/)) { 163 $icon = $1; 164 open(FH, "ENVCAN_icons") or die "Cannot open icons"; 165 while (my $line = <FH>) { 166 chomp $line; 167 if ($line =~ /$icon\:\:(.*)/) { 168 $icon = $1; 169 last; 170 } 171 } 172 close (FH); 60 else { 61 $icon = 'unknown.png'; 173 62 } 174 175 # Current conditions176 $results{"weather_icon"} = $icon177 if (defined($inside{'img-class'})178 && ($inside{'img-class'} eq "currentimg"));179 $results{"icon-0"} = $icon180 if (defined($inside{'img-longdesc'})181 && ($inside{'img-longdesc'} eq "#f1"));182 $results{"icon-1"} = $icon183 if (defined($inside{'img-longdesc'})184 && ($inside{'img-longdesc'} eq "#f2"));185 $results{"icon-2"} = $icon186 if (defined($inside{'img-longdesc'})187 && ($inside{'img-longdesc'} eq "#f3"));188 $results{"icon-3"} = $icon189 if (defined($inside{'img-longdesc'})190 && ($inside{'img-longdesc'} eq "#f4"));191 $results{"icon-4"} = $icon192 if (defined($inside{'img-longdesc'})193 && ($inside{'img-longdesc'} eq "#f5"));194 $results{"icon-5"} = $icon195 if (defined($inside{'img-longdesc'})196 && ($inside{'img-longdesc'} eq "#f6"));197 63 198 undef ($inside{'img-class'}); 199 undef ($inside{'img-src'}); 200 undef ($inside{'img-longdesc'}); 201 undef ($inside{'img'}); 64 return $icon; 202 65 } 203 66 204 sub rfc822 { 205 my ($string) = @_; 67 sub doParse { 206 68 207 if ($string =~ /(\d*):(\d*) (AM|PM) (...) \w* (\d*) (\w*) (\d*)/) { 208 my $hour = int($1) - 1; 209 my $min = int($2); 210 my $ampm = $3; 211 my $tzone = $4; 212 my $day = $5; 213 my $month = $6; 214 my $year = $7; 69 my ($data, @types) = @_; 215 70 216 if ($ampm eq "PM") { if (int($hour) < 11) { $hour += 12; } } 217 $month = 0 if $month eq "January"; 218 $month = 1 if $month eq "February"; 219 $month = 2 if $month eq "March"; 220 $month = 3 if $month eq "April"; 221 $month = 4 if $month eq "May"; 222 $month = 5 if $month eq "June"; 223 $month = 6 if $month eq "July"; 224 $month = 7 if $month eq "August"; 225 $month = 8 if $month eq "September"; 226 $month = 9 if $month eq "October"; 227 $month = 10 if $month eq "November"; 228 $month = 11 if $month eq "December"; 229 $year = int($year) - 1900; 71 # Initialize results hash 72 foreach my $type (@types) { $results{$type} = ""; } 230 73 231 my $time_t = POSIX::mktime(0, $min, $hour, $day, $month, $year);232 my $now_string = localtime($time_t);74 my $xml = XMLin($data); 75 die if (!$xml); 233 76 234 return $now_string; 77 $results{'copyright'} = $xml->{channel}->{copyright}; 78 if ($xml->{channel}->{title} =~ /^(.*) - Weather/) { 79 $results{'cclocation'} = ucfirst($1); 80 $results{'3dlocation'} = ucfirst($1); 81 $results{'6dlocation'} = ucfirst($1); 235 82 } 83 84 my $i = 0; 85 foreach my $item (@{$xml->{channel}->{item}}) { 86 if ($item->{title} =~ /Current Conditions/) { 87 if ($item->{description} =~ /Condition:\<\/b\>\s*([\w ]*)\s*\<br\/\>/s) { 88 $results{'weather'} = $1; 89 $results{'weather_icon'} = getIcon($1); 90 } 91 $results{'temp'} = sprintf("%.0f", $1) 92 if ($item->{description} =~ /Temperature:\<\/b\>\s*(-?\d*\.?\d*)\260\C\s*\<br\/\>/s); 93 $results{'pressure'} = sprintf("%d", $1 * 10) 94 if ($item->{description} =~ /Pressure \/ Tendency:\<\/b\>\s*(\d*\.?\d*) kPa\s*.*\<br\/\>/s); 95 $results{'visibility'} = sprintf("%.1f", $1) 96 if ($item->{description} =~ /Visibility:\<\/b\>\s*(\d*\.?\d*) km\s*.*\<br\/\>/s); 97 $results{'relative_humidity'} = $1 98 if ($item->{description} =~ /Humidity:\<\/b\>\s*(\d*) \%\<br\/\>/s); 99 if ($item->{description} =~ /Wind Chill:\<\/b\>\s*(-?\d*\.?\d*)\s*\<br\/\>/s) { 100 $results{'appt'} = $1; 101 $results{'windchill'} = $1; 102 } 103 $results{'dewpoint'} = sprintf("%.0f", $1) 104 if ($item->{description} =~ /Dewpoint:\<\/b\>\s*(-?\d*\.?\d*)\260\C\s*\<br\/\>/s); 105 if ($item->{description} =~ /(\d*\:\d*[\w ]*\d*[\w *]\d*)\s*\<br\/\>/s) { 106 $results{'observation_time'} = "Last updated at ". $1; 107 $results{'updatetime'} = "Last updated at ". $1; 108 } 109 if ($item->{description} =~ /Wind:\<\/b\>(.*)\<br\/\>/s) { 110 my $wind = $1; 111 if ($wind =~ /\s*(\d*)\s*km\/h\s*/i) { 112 $results{'wind_dir'} = 'Calm'; 113 $results{'wind_speed'} = $1; 114 $results{'wind_gust'} = 0; 115 } 116 if ($wind =~ /\s*(\w*)\s*(\d*)\s*km\/h\s*/i) { 117 $results{'wind_dir'} = $directions{$1}; 118 $results{'wind_speed'} = $2; 119 } 120 if ($wind =~ /\s*(\w*)\s*(\d*)\s*km\/h\s*gust\s*(\d*)\s*km\/h/i) { 121 $results{'wind_gust'} = $3; 122 } 123 } 124 next; 125 } 236 126 237 return ""; 127 if ($item->{title} =~ /^(.*):\s*([\w ]*)\.\s*(.*)/) { 128 my $day = $1; 129 my $condition = $2; 130 my $high_low = $3; 131 my $temp; 238 132 239 } 133 $results{"date-$i"} = $day; 134 $results{"icon-$i"} = getIcon($condition); 240 135 241 sub postProcess { 242 # In the morning, Environment Canada doesn't report these variables: 243 # low-0, high-1, low-2 244 # Here we assume what they should be... 136 if ($high_low =~ /high (\w*) (\d*)/i) { 137 $temp = $2; 138 if ($1 =~ /minus/i) { $temp = ($temp * -1); } 139 $results{"high-$i"} = $temp; 140 } 245 141 246 if (($results{'low-0'} eq "NA") 247 && ($results{'low-1'} <= $results{'high-0'})) { 248 $results{'low-0'} = $results{'low-1'}; 249 } 250 if (($results{'high-1'} eq "NA") 251 && ($results{'high-0'} >= $results{'low-1'})) { 252 $results{'high-1'} = $results{'high-0'}; 253 } 254 if (($results{'low-2'} eq "NA") 255 && ($results{'low-1'} <= $results{'high-2'})) { 256 $results{'low-2'} = $results{'low-1'}; 257 } 142 if ($high_low =~ /steady near (\w*) (\d*)/i) { 143 $temp = $2; 144 if ($1 =~ /minus/i) { $temp = ($temp * -1); } 145 $results{"high-$i"} = $temp; 146 } 258 147 259 # In the afternoon, Environment Canada doesn't report these variables: 260 # 261 # high-0, low-1, high-2, low-3 262 # Here we assume what they should be... 263 if (($results{'high-0'} eq "NA") 264 && ($results{'temp'} >= $results{'low-0'})) { 265 $results{'high-0'} = $results{'temp'}; 148 if ($high_low =~ /low (\w*) (\d*)/i) { 149 $temp = $2; 150 if ($1 =~ /minus/i) { $temp = ($temp * -1); } 151 $results{"low-$i"} = $temp; 152 } 153 154 $results{"high-$i"} = 0 if ($high_low =~ /high zero/i); 155 $results{"low-$i"} = 0 if ($high_low =~ /low zero/i); 156 157 $i++; 158 } 266 159 } 267 if (($results{'low-1'} eq "NA")268 && ($results{'low-2'} <= $results{'high-1'})) {269 $results{'low-1'} = $results{'low-2'};270 }271 if (($results{'high-2'} eq "NA")272 && ($results{'high-1'} >= $results{'low-2'})) {273 $results{'high-2'} = $results{'high-1'};274 }275 if (($results{'low-3'} eq "NA")276 && ($results{'low-2'} <= $results{'high-3'})) {277 $results{'low-3'} = $results{'low-2'};278 }279 }280 160 281 sub doParse { 161 # Correct for Environment Canada's temperature methods 162 $results{'low-0'} = $results{'low-1'} if (!length($results{'low-0'})); 163 $results{'low-1'} = $results{'low-0'} if (!length($results{'low-1'})); 164 $results{'low-2'} = $results{'low-1'} if (!length($results{'low-2'})); 165 $results{'low-3'} = $results{'low-4'} if (!length($results{'low-3'})); 166 $results{'high-0'} = $results{'temp'} if (!length($results{'high-0'}) && 167 ($results{'temp'} >= $results{'low-0'})); 168 $results{'high-1'} = $results{'high-0'} if (!length($results{'high-1'})); 169 $results{'high-2'} = $results{'high-1'} if (!length($results{'high-2'})); 282 170 283 my ($data, @types) = @_;284 285 # Initialize results hash286 foreach my $type (@types) { $results{$type} = "NA"; }287 288 my $p = HTML::Parser->new(api_version => 3);289 $p->unbroken_text(1);290 $p->report_tags(qw(div dd dt h2 h3 img li p title));291 $p->ignore_elements(qw(style script));292 $p->handler( start => \&start_h, 'tagname, @attr');293 $p->handler( end => \&end_h, "tagname");294 $p->handler( text => \&text, "dtext");295 $p->parse($data) || die $!;296 297 # Do some post-processing to handle Environment Canada weirdness298 postProcess();299 300 171 return %results; 301 172 } 302 173 -
mythplugins/mythweather/mythweather/scripts/ENVCANMapSearch.pm
40 40 if ($name eq 'entry') { 41 41 $expat->{CurrEntry} = {}; 42 42 $expat->{MatchFound} = 0; 43 43 } 44 44 } 45 45 46 46 sub Text { … … 99 99 100 100 elsif ($expat->in_element('animated_url')) { 101 101 $expat->{CurrEntry}->{animated_url} = $text; 102 102 } 103 103 } 104 104 105 105 sub EndTag {