Ticket #7024: 7024.diff
File 7024.diff, 12.1 KB (added by , 15 years ago) |
---|
-
trunk/mythplugins/mythweather/mythweather/scripts/uk_bbc/bbccurrentxml.pl
18 18 our ($opt_v, $opt_t, $opt_T, $opt_l, $opt_u, $opt_d); 19 19 20 20 my $name = 'BBC-Current-XML'; 21 my $version = 0. 1;21 my $version = 0.2; 22 22 my $author = 'Stuart Morgan'; 23 23 my $email = 'stuart@tase.co.uk'; 24 24 my $updateTimeout = 120*60; … … 74 74 } 75 75 76 76 my $units = $opt_u; 77 my $base_url; 77 my $base_url = 'http://newsrss.bbc.co.uk/weather/forecast/'; 78 my $base_xml = '/ObservationsRSS.xml'; 78 79 79 my $local_base_url = 'http://feeds.bbc.co.uk/weather/feeds/rss/obs/id/'; 80 my $world_base_url = 'http://feeds.bbc.co.uk/weather/feeds/rss/obs/world/'; 81 82 if ($locid =~ s/^W(.*)/$1/) 80 if ($locid =~ s/^(\d*)/$1/) 83 81 { 84 $base_url = $ world_base_url;82 $base_url = $base_url . $1 .$base_xml; 85 83 } 86 elsif ($locid =~ s/^L(.*)/$1/)87 {88 $base_url = $local_base_url;89 }90 84 else 91 85 { 92 86 die "Invalid Location ID"; 93 87 } 94 88 95 my $response = get $base_url . $locid . '.xml';89 my $response = get $base_url; 96 90 die unless defined $response; 97 91 98 92 my $xml = XMLin($response); … … 111 105 printf "cclocation::" . $location . "\n"; 112 106 113 107 my $item_title = $xml->{channel}->{item}->{title}; 114 $item_title =~ s/\n//;115 108 116 my $obs_time = $item_title; 117 $obs_time =~ s/^(.*?)\:.*/$1/s; 109 my $obs_time = $1 if ($item_title =~ /(^.*)\:.*/); 118 110 printf "observation_time::" . $obs_time . "\n"; 119 111 my $weather_string = $item_title; 120 $weather_string =~ s/.*?\: (.*?)\..*/$1/s; 112 113 $weather_string =~ s/.*\:.*\n(.*)\..*/$1/s; 121 114 $weather_string = ucfirst($weather_string); 122 115 printf "weather::" . $weather_string . "\n"; 123 116 124 if ($weather_string =~ /^cloudy$/i) { 117 if ($weather_string =~ /^cloudy$/i || 118 $weather_string =~ /^grey cloud$/i || 119 $weather_string =~ /^white cloud$/i) { 125 120 printf "weather_icon::cloudy.png\n"; 126 121 } 127 elsif ($weather_string =~ /^foggy$/i || 128 $weather_string =~ /^misty$/i) { 122 elsif ($weather_string =~ /^fog$/i || 123 $weather_string =~ /^foggy$/i || 124 $weather_string =~ /^mist$/i || 125 $weather_string =~ /^misty$/i) { 129 126 printf "weather_icon::fog.png\n"; 130 127 } 131 128 elsif ($weather_string =~ /^sunny$/i) { 132 129 printf "weather_icon::sunny.png\n"; 133 130 } 134 131 elsif ($weather_string =~ /^sunny intervals$/i || 135 132 $weather_string =~ /^partly cloudy$/i) { 136 133 printf "weather_icon::pcloudy.png\n"; 137 134 } 138 135 elsif ($weather_string =~ /^drizzle$/i || 139 $weather_string =~ /^light rain$/i || 140 $weather_string =~ /^light showers$/i) { 136 $weather_string =~ /^light rain$/i || 137 $weather_string =~ /^light rain showers?$/i || 138 $weather_string =~ /^light showers?$/i) { 141 139 printf "weather_icon::lshowers.png\n"; 142 140 } 143 elsif ($weather_string =~ /^heavy rain$/i || 144 $weather_string =~ /^heavy showers$/i) { 141 elsif ($weather_string =~ /^heavy rain$/i || 142 $weather_string =~ /^heavy showers?$/i || 143 $weather_string =~ /^heavy rain showers?$/i) { 145 144 printf "weather_icon::showers.png\n"; 146 145 } 147 146 elsif ($weather_string =~ /^thundery rain$/i || 148 $weather_string =~ /^thundery showers$/i) { 147 $weather_string =~ /^thunder storm$/i || 148 $weather_string =~ /^thundery showers$/i) { 149 149 printf "weather_icon::thunshowers.png\n"; 150 150 } 151 151 elsif ($weather_string =~ /^heavy snow$/i) { … … 156 156 printf "weather_icon::flurries.png\n"; 157 157 } 158 158 elsif ($weather_string =~ /^sleet$/i || 159 $weather_string =~ /^sleet showers $/i ||160 $weather_string =~ /^hail showers $/i) {159 $weather_string =~ /^sleet showers?$/i || 160 $weather_string =~ /^hail showers?$/i) { 161 161 printf "weather_icon::rainsnow.png\n"; 162 162 } 163 elsif ($weather_string =~ /^clear$/i) { 163 elsif ($weather_string =~ /^clear$/i || 164 $weather_string =~ /^clear sky$/i) { 164 165 printf "weather_icon::fair.png\n"; 165 166 } 166 167 else { … … 187 188 } 188 189 elsif ($datalabel =~ /Wind Speed/) { 189 190 $datalabel = "wind_spdgst"; 190 $datavalue =~ s/^(\d{1,3}) 191 $datavalue =~ s/^(\d{1,3})mph.*/$1/; 191 192 192 193 if ($units =~ /SI/) { 193 194 $datavalue = int($datavalue * 1.609344 + .5); -
trunk/mythplugins/mythweather/mythweather/scripts/uk_bbc/bbcthreedayxml.pl
71 71 } 72 72 73 73 my $units = $opt_u; 74 my $base_url; 75 my $local_base_url = 'http://feeds.bbc.co.uk/weather/feeds/rss/5day/id/'; 76 my $world_base_url = 'http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/'; 74 my $base_url = 'http://newsrss.bbc.co.uk/weather/forecast/'; 75 my $base_xml = '/Next3DaysRSS.xml'; 77 76 78 if ($locid =~ s/^ W(.*)/$1/)77 if ($locid =~ s/^(\d*)/$1/) 79 78 { 80 $base_url = $ world_base_url;79 $base_url = $base_url . $1 . $base_xml; 81 80 } 82 elsif ($locid =~ s/^L(.*)/$1/)83 {84 $base_url = $local_base_url;85 }86 81 else 87 82 { 88 83 die "Invalid Location ID"; 89 84 } 90 85 91 my $response = get $base_url . $locid . '.xml'; 86 87 my $response = get $base_url; 92 88 die unless defined $response; 93 89 94 90 my $xml = XMLin($response); … … 143 139 $weather_string =~ s/.*?\: (.*?),.*/$1/s; 144 140 $weather_string = ucfirst($weather_string); 145 141 146 if ($weather_string =~ /^cloudy$/i) { 142 if ($weather_string =~ /^cloudy$/i || 143 $weather_string =~ /^grey cloud$/i || 144 $weather_string =~ /^white cloud$/i) { 147 145 printf "icon-" . $i . "::cloudy.png\n"; 148 146 } 149 elsif ($weather_string =~ /^foggy$/i || 147 elsif ($weather_string =~ /^fog$/i || 148 $weather_string =~ /^foggy$/i || 149 $weather_string =~ /^mist$/i || 150 150 $weather_string =~ /^misty$/i) { 151 151 printf "icon-" . $i . "::fog.png\n"; 152 152 } … … 159 159 } 160 160 elsif ($weather_string =~ /^drizzle$/i || 161 161 $weather_string =~ /^light rain$/i || 162 $weather_string =~ /^light showers$/i) { 162 $weather_string =~ /^light rain showers?$/i || 163 $weather_string =~ /^light showers?$/i) { 163 164 printf "icon-" . $i . "::lshowers.png\n"; 164 165 } 165 elsif ($weather_string =~ /^heavy rain$/i || 166 $weather_string =~ /^heavy showers$/i) { 166 elsif ($weather_string =~ /^heavy rain$/i || 167 $weather_string =~ /^heavy showers?$/i || 168 $weather_string =~ /^heavy rain showers?$/i) { 167 169 printf "icon-" . $i . "::showers.png\n"; 168 170 } 169 171 elsif ($weather_string =~ /^thundery rain$/i || 172 $weather_string =~ /^thunder storm$/i || 170 173 $weather_string =~ /^thundery showers$/i) { 171 174 printf "icon-" . $i . "::thunshowers.png\n"; 172 175 } … … 178 181 printf "icon-" . $i . "::flurries.png\n"; 179 182 } 180 183 elsif ($weather_string =~ /^sleet$/i || 181 $weather_string =~ /^sleet showers $/i ||182 $weather_string =~ /^hail showers $/i) {184 $weather_string =~ /^sleet showers?$/i || 185 $weather_string =~ /^hail showers?$/i) { 183 186 printf "icon-" . $i . "::rainsnow.png\n"; 184 187 } 185 elsif ($weather_string =~ /^clear$/i) { 188 elsif ($weather_string =~ /^clear$/i || 189 $weather_string =~ /^clear sky$/i) { 186 190 printf "icon-" . $i . "::fair.png\n"; 187 191 } 188 192 else { -
trunk/mythplugins/mythweather/mythweather/scripts/uk_bbc/BBCLocation.pm
4 4 use LWP::Simple; 5 5 6 6 our @EXPORT = qw(Search); 7 our $VERSION = 0. 1;7 our $VERSION = 0.2; 8 8 9 9 my @searchresults; 10 my @resulturl; 11 my $resultcount = -1; 10 12 11 13 sub Search { 12 14 13 my $base_url = 'http://www.bbc.co.uk/cgi-perl/weather/search/new_search.pl?search_query='; 15 my $base_url = 'http://news.bbc.co.uk/weather/forecast/'; 16 my $world_base_url = $base_url . '?lowgraphics=true&search='; 17 my $local_base_url = $base_url . '?lowgraphics=true&type=county_state&search='; 14 18 15 19 my $search_string = shift; 16 20 17 my $response = get $base_url . $search_string; 18 die unless defined $response; 21 my $world_response = get $world_base_url . $search_string; 22 die unless defined $world_response; 23 my $local_response = get $local_base_url . $search_string; 24 die unless defined $local_response; 19 25 20 my $isresults = 0; 21 my $isredirect = 0; 22 my $isworld = 0; 26 &parseResults($world_response); 27 &parseResults($local_response); 23 28 29 if ( ($resultcount > 0 ) && ($#searchresults < 0) ) { 30 foreach my $url (@resulturl) { 31 my $url_response = get $base_url . $url; 32 die unless defined $url_response; 33 &parseResults($url_response); 34 } 35 } 36 37 return @searchresults; 38 } 39 40 sub parseResults { 41 my $response = shift; 42 my $isresults = 0; 24 43 my $havename = 0; 25 44 my $haveid = 0; 26 27 45 my $resultline = ""; 28 46 29 47 foreach (split("\n", $response)) { 30 if (/< title>.*?Search Results.*?<\/title>/) {48 if (/<p class=\"response\">/) { 31 49 $isresults = 1; 32 50 } 33 else {34 $isredirect = 1;35 }36 51 37 52 my $locname; 38 my $locid; 53 my $locid; 54 my $url; 39 55 40 56 if ($isresults) { 57 last if (/There are no forecasts matching/); 41 58 42 if (/No locations were found/) { 43 last; 44 } 45 elsif (/if query returns results close/) { 46 last; 47 } 48 elsif (/non UK towns results open/) { 49 $isworld = 1; 50 } 51 elsif (/\/weather\/5day\.shtml\?id=/) { 52 $locid = $_; 53 $locid =~ s/.*?\?id=(\d{0,4}).*/$1/s; 59 $resultcount = $1 if (/<strong>There \w{2,3} (\d*) forecasts? matching/); 54 60 55 $locname = $_;56 $locname =~ s/.*?<strong>(.*?)<.*/$1/s;57 58 $ resultline = "L" . $locid . "::" . $locname . ", United Kingdom";59 push (@ searchresults, $resultline);61 # Collect result URLs 62 if (/<a id=\"result_\d*\" href \=\"?.*search\=.*/) { 63 $url = $_; 64 $url =~ s/.*href \=\"(.*)\".*/$1/s; 65 push (@resulturl, $url); 60 66 } 61 elsif (/\/weather\/5day\.shtml\?world=/) {62 $locid = $_;63 $locid =~ s/.*?\?world=(\d{4}).*/$1/s;64 67 68 # Collect location IDs and location names 69 elsif (/<a id=\"result_\d*\" href \=\"\/weather\/forecast\//) { 70 $locid = $_; 71 $locid =~ s/.*\/weather\/forecast\/(\d{0,5})\?.*/$1/s; 72 65 73 $locname = $_; 66 $locname =~ s/.* ?<strong>(.*?)<.*/$1/s;74 $locname =~ s/.*<a id=\"result_\d*\".*>(.*)<\/a>.*/$1/s; 67 75 68 $resultline = "W" . $locid . "::" . $locname; 69 70 unless ($isworld) { 71 $resultline = $resultline . ", United Kingdom"; 72 push (@searchresults, $resultline); 73 } 74 } 75 elsif ($isworld && /<\/a><\/strong>/) { 76 my $country = $_; 77 $country =~ s/.*?>([a-zA-Z ,']*)<\/a><\/strong>.*/$1/; 78 $resultline = $resultline . ", " . $country; 76 $resultline = $locid . "::" . $locname; 79 77 push (@searchresults, $resultline); 80 78 } 81 82 79 } 83 elsif ($isredirect) {84 if (/name : \"/) {85 my $locname = $_;86 $locname =~ s/^.*name : \"(.*?)\".*$/$1/;87 $resultline = $resultline . "::" . $locname . ", United Kingdom";88 $havename = 1;89 }90 if (/rssloc :/) {91 my $id = 0;92 $id = s/.*rssloc : (\d{4}),.*/$1/;93 $resultline = "W" . $_ . $resultline;94 $haveid = 1;95 }96 }97 80 98 81 if ($havename && $haveid) { 99 82 push (@searchresults, $resultline);