Ticket #7758: 7758.diff

File 7758.diff, 2.8 KB (added by Joe Ripley <vitaminjoe@…>, 11 years ago)

Patch to fix BBC Locations searches

  • mythplugins/mythweather/mythweather/scripts/uk_bbc/BBCLocation.pm

     
    1212
    1313sub Search {
    1414
    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=';
     15    my $base_url       = 'http://news.bbc.co.uk/weather/util/search/Search.xhtml?';
     16    my $world_base_url = $base_url . 'lowgraphics=true&region=world&search=';
     17    my $local_base_url = $base_url . 'lowgraphics=true&region=uk&search=';
    1818
    1919    my $search_string = shift;
    2020
    2121    my $world_response = get $world_base_url . $search_string;
    22     die unless defined $world_response;
    2322    my $local_response = get $local_base_url . $search_string;
    24     die unless defined $local_response;
    2523
    26     &parseResults($world_response);
    27     &parseResults($local_response);
     24    &parseResults($world_response) if defined($world_response);
     25    &parseResults($local_response) if defined($local_response);
    2826
    2927    if ( ($resultcount > 0 ) && ($#searchresults < 0) ) {
    3028        foreach my $url (@resulturl) {
     
    4038sub parseResults {
    4139    my $response = shift;
    4240    my $isresults = 0;
    43     my $havename = 0;
    44     my $haveid = 0;
    4541    my $resultline = "";
    4642
    4743    foreach (split("\n", $response)) {
     
    5955            $resultcount = $1 if (/<strong>There \w{2,3} (\d*) forecasts? matching/);
    6056
    6157            # Collect result URLs
    62             if (/<a id=\"result_\d*\" href \=\"?.*search\=.*/) {
     58            if (/<a id=\"result_\d*\" .* href \=\"?.*search\=.*/) {
    6359                $url = $_;
    6460                $url =~ s/.*href \=\"(.*)\".*/$1/s;
    6561                push (@resulturl, $url);
    6662            }
    6763
    6864            # Collect location IDs and location names
    69             elsif (/<a id=\"result_\d*\" href \=\"\/weather\/forecast\//) {
     65            elsif (/<a id=\"result_\d*\" .* href \=\"\/weather\/forecast\//) {
    7066                $locid = $_;
    7167                $locid =~ s/.*\/weather\/forecast\/(\d{0,5})\?.*/$1/s;
    7268       
     
    7470                $locname =~ s/.*<a id=\"result_\d*\".*>(.*)<\/a>.*/$1/s;
    7571
    7672                $resultline = $locid . "::" . $locname;
    77                 push (@searchresults, $resultline);
     73                if (! grep(/^$locid/, @searchresults)) {
     74                    push (@searchresults, $resultline);
     75                }
    7876            }
    7977        }
    80 
    81         if ($havename && $haveid) {
    82             push (@searchresults, $resultline);
    83             last;
    84         }
    8578    }
    8679
    8780    return @searchresults;