Ticket #7024: 7024.diff

File 7024.diff, 12.1 KB (added by Joe Ripley <vitaminjoe@…>, 15 years ago)

Update BBC grabber to function with new RSS feeds

  • trunk/mythplugins/mythweather/mythweather/scripts/uk_bbc/bbccurrentxml.pl

     
    1818our ($opt_v, $opt_t, $opt_T, $opt_l, $opt_u, $opt_d);
    1919
    2020my $name = 'BBC-Current-XML';
    21 my $version = 0.1;
     21my $version = 0.2;
    2222my $author = 'Stuart Morgan';
    2323my $email = 'stuart@tase.co.uk';
    2424my $updateTimeout = 120*60;
     
    7474}
    7575
    7676my $units = $opt_u;
    77 my $base_url;
     77my $base_url = 'http://newsrss.bbc.co.uk/weather/forecast/';
     78my $base_xml = '/ObservationsRSS.xml';
    7879
    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/)
     80if ($locid =~ s/^(\d*)/$1/)
    8381{
    84     $base_url = $world_base_url;
     82    $base_url = $base_url . $1 .$base_xml;
    8583}
    86 elsif ($locid =~ s/^L(.*)/$1/)
    87 {
    88     $base_url = $local_base_url;
    89 }
    9084else
    9185{
    9286    die "Invalid Location ID";
    9387}
    9488
    95 my $response = get $base_url . $locid . '.xml';
     89my $response = get $base_url;
    9690die unless defined $response;
    9791
    9892my $xml = XMLin($response);
     
    111105printf "cclocation::" . $location . "\n";
    112106
    113107my $item_title = $xml->{channel}->{item}->{title};
    114 $item_title =~ s/\n//;
    115108
    116 my $obs_time = $item_title;
    117 $obs_time =~ s/^(.*?)\:.*/$1/s;
     109my $obs_time = $1 if ($item_title =~ /(^.*)\:.*/);
    118110printf "observation_time::" . $obs_time . "\n";
    119111my $weather_string = $item_title;
    120 $weather_string =~ s/.*?\: (.*?)\..*/$1/s;
     112
     113$weather_string =~ s/.*\:.*\n(.*)\..*/$1/s;
    121114$weather_string = ucfirst($weather_string);
    122115printf "weather::" . $weather_string . "\n";
    123116
    124 if ($weather_string =~ /^cloudy$/i) {
     117if ($weather_string =~ /^cloudy$/i     ||
     118    $weather_string =~ /^grey cloud$/i ||
     119    $weather_string =~ /^white cloud$/i) {
    125120    printf "weather_icon::cloudy.png\n";
    126121}
    127 elsif ($weather_string =~ /^foggy$/i ||
    128        $weather_string =~ /^misty$/i) {
     122elsif ($weather_string =~ /^fog$/i ||
     123    $weather_string =~ /^foggy$/i  ||
     124    $weather_string =~ /^mist$/i   ||
     125    $weather_string =~ /^misty$/i) {
    129126    printf "weather_icon::fog.png\n";
    130127}
    131128elsif ($weather_string =~ /^sunny$/i) {
    132129    printf "weather_icon::sunny.png\n";
    133130}
    134131elsif ($weather_string =~ /^sunny intervals$/i ||
    135        $weather_string =~ /^partly cloudy$/i) {
     132    $weather_string =~ /^partly cloudy$/i) {
    136133    printf "weather_icon::pcloudy.png\n";
    137134}
    138135elsif ($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) {
    141139    printf "weather_icon::lshowers.png\n";
    142140}
    143 elsif ($weather_string =~ /^heavy rain$/i ||
    144        $weather_string =~ /^heavy showers$/i) {
     141elsif ($weather_string =~ /^heavy rain$/i  ||
     142    $weather_string =~ /^heavy showers?$/i ||
     143    $weather_string =~ /^heavy rain showers?$/i) {
    145144    printf "weather_icon::showers.png\n";
    146145}
    147146elsif ($weather_string =~ /^thundery rain$/i ||
    148        $weather_string =~ /^thundery showers$/i) {
     147    $weather_string =~ /^thunder storm$/i    ||
     148    $weather_string =~ /^thundery showers$/i) {
    149149    printf "weather_icon::thunshowers.png\n";
    150150}
    151151elsif ($weather_string =~ /^heavy snow$/i) {
     
    156156    printf "weather_icon::flurries.png\n";
    157157}
    158158elsif ($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) {
    161161    printf "weather_icon::rainsnow.png\n";
    162162}
    163 elsif ($weather_string =~ /^clear$/i) {
     163elsif ($weather_string =~ /^clear$/i ||
     164       $weather_string =~ /^clear sky$/i) {
    164165    printf "weather_icon::fair.png\n";
    165166}
    166167else {
     
    187188    }
    188189    elsif ($datalabel =~ /Wind Speed/) {
    189190        $datalabel = "wind_spdgst";
    190         $datavalue =~ s/^(\d{1,3}) mph.*/$1/;
     191        $datavalue =~ s/^(\d{1,3})mph.*/$1/;
    191192
    192193        if ($units =~ /SI/) {
    193194            $datavalue = int($datavalue * 1.609344 + .5);
  • trunk/mythplugins/mythweather/mythweather/scripts/uk_bbc/bbcthreedayxml.pl

     
    7171}
    7272
    7373my $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/';
     74my $base_url = 'http://newsrss.bbc.co.uk/weather/forecast/';
     75my $base_xml = '/Next3DaysRSS.xml';
    7776
    78 if ($locid =~ s/^W(.*)/$1/)
     77if ($locid =~ s/^(\d*)/$1/)
    7978{
    80     $base_url = $world_base_url;
     79    $base_url = $base_url . $1 . $base_xml;
    8180}
    82 elsif ($locid =~ s/^L(.*)/$1/)
    83 {
    84     $base_url = $local_base_url;
    85 }
    8681else
    8782{
    8883    die "Invalid Location ID";
    8984}
    9085
    91 my $response = get $base_url . $locid . '.xml';
     86
     87my $response = get $base_url;
    9288die unless defined $response;
    9389
    9490my $xml = XMLin($response);
     
    143139    $weather_string =~ s/.*?\: (.*?),.*/$1/s;
    144140    $weather_string = ucfirst($weather_string);
    145141
    146     if ($weather_string =~ /^cloudy$/i) {
     142    if ($weather_string =~ /^cloudy$/i     ||
     143        $weather_string =~ /^grey cloud$/i ||
     144        $weather_string =~ /^white cloud$/i) {
    147145        printf "icon-" . $i . "::cloudy.png\n";
    148146    }
    149     elsif ($weather_string =~ /^foggy$/i ||
     147    elsif ($weather_string =~ /^fog$/i ||
     148        $weather_string =~ /^foggy$/i  ||
     149        $weather_string =~ /^mist$/i   ||
    150150        $weather_string =~ /^misty$/i) {
    151151        printf "icon-" . $i . "::fog.png\n";
    152152    }
     
    159159    }
    160160    elsif ($weather_string =~ /^drizzle$/i ||
    161161        $weather_string =~ /^light rain$/i ||
    162         $weather_string =~ /^light showers$/i) {
     162        $weather_string =~ /^light rain showers?$/i ||
     163        $weather_string =~ /^light showers?$/i) {
    163164        printf "icon-" . $i . "::lshowers.png\n";
    164165    }
    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) {
    167169        printf "icon-" . $i . "::showers.png\n";
    168170    }
    169171    elsif ($weather_string =~ /^thundery rain$/i ||
     172        $weather_string =~ /^thunder storm$/i    ||
    170173        $weather_string =~ /^thundery showers$/i) {
    171174        printf "icon-" . $i . "::thunshowers.png\n";
    172175    }
     
    178181        printf "icon-" . $i . "::flurries.png\n";
    179182    }
    180183    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) {
    183186        printf "icon-" . $i . "::rainsnow.png\n";
    184187    }
    185     elsif ($weather_string =~ /^clear$/i) {
     188    elsif ($weather_string =~ /^clear$/i ||
     189           $weather_string =~ /^clear sky$/i) {
    186190        printf "icon-" . $i . "::fair.png\n";
    187191    }
    188192    else {
  • trunk/mythplugins/mythweather/mythweather/scripts/uk_bbc/BBCLocation.pm

     
    44use LWP::Simple;
    55
    66our @EXPORT = qw(Search);
    7 our $VERSION = 0.1;
     7our $VERSION = 0.2;
    88
    99my @searchresults;
     10my @resulturl;
     11my $resultcount = -1;
    1012
    1113sub Search {
    1214
    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=';
    1418
    1519    my $search_string = shift;
    1620
    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;
    1925
    20     my $isresults = 0;
    21     my $isredirect = 0;
    22     my $isworld = 0;
     26    &parseResults($world_response);
     27    &parseResults($local_response);
    2328
     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
     40sub parseResults {
     41    my $response = shift;
     42    my $isresults = 0;
    2443    my $havename = 0;
    2544    my $haveid = 0;
    26 
    2745    my $resultline = "";
    2846
    2947    foreach (split("\n", $response)) {
    30         if (/<title>.*?Search Results.*?<\/title>/) {
     48        if (/<p class=\"response\">/) {
    3149            $isresults = 1;
    3250        }
    33         else {
    34             $isredirect = 1;
    35         }
    3651
    3752        my $locname;
    38         my $locid;
     53        my $locid;
     54        my $url;
    3955
    4056        if ($isresults) {
     57            last if (/There are no forecasts matching/);
    4158
    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/);
    5460
    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);
    6066            }
    61             elsif (/\/weather\/5day\.shtml\?world=/) {
    62                 $locid = $_;
    63                 $locid =~ s/.*?\?world=(\d{4}).*/$1/s;
    6467
     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       
    6573                $locname = $_;
    66                 $locname =~ s/.*?<strong>(.*?)<.*/$1/s;
     74                $locname =~ s/.*<a id=\"result_\d*\".*>(.*)<\/a>.*/$1/s;
    6775
    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;
    7977                push (@searchresults, $resultline);
    8078            }
    81 
    8279        }
    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         }
    9780
    9881        if ($havename && $haveid) {
    9982            push (@searchresults, $resultline);