Ticket #7999: BBCLocation.patch
File BBCLocation.patch, 2.3 KB (added by , 14 years ago) |
---|
-
BBCLocation.
old new 39 39 my $response = shift; 40 40 my $isresults = 0; 41 41 my $resultline = ""; 42 43 # Initialise a hash for the $locid & $locname results. 44 45 # Use of a hash indexed by $locid ensures that more informative results 46 # (e.g. "Sale, Australia" vs. "Sale") coming from <p class="response"> 47 # section will overwrite less informative results coming from 48 # <span id="printbutton_Forecast"> section 49 50 my %loc_hash = (); 42 51 43 52 foreach (split("\n", $response)) { 44 if (/<p class=\"response\">/) { 53 54 # Declare a result if either the '<p class="response"> OR <span id="printbutton_Forecast"> strings are found 55 # This ensures that single and multiple matches are caught 56 57 if (/<p class=\"response\">/ || /<span id=\"printbutton_Forecast\">/) { 45 58 $isresults = 1; 46 59 } 47 60 48 61 my $locname; 49 62 my $locid; 50 63 my $url; 51 64 52 65 if ($isresults) { 53 66 last if (/There are no forecasts matching/); 54 67 … … 70 83 $locname =~ s/.*<a id=\"result_\d*\".*>(.*)<\/a>.*/$1/s; 71 84 72 85 $resultline = $locid . "::" . $locname; 73 if (! grep(/^$locid/, @searchresults)) { 74 push (@searchresults, $resultline); 75 } 86 87 $loc_hash{$locid} = $locname; 76 88 } 89 90 # Extract location ID and name from "Print <location>" link 91 92 # This string is always present (provided valid search result - invalid results are caught above) 93 # irresepective of whether single or multiple matches are returned 94 95 elsif (/<span id=\"printbutton_Forecast\"><a title=\"Print (.+)\" href=\"\/weather\/forecast\/(\d{0,5})?/o) 96 { 97 $locid = $2; 98 $locname = $1; 99 100 $loc_hash{$locid} = $locname; 101 } 77 102 } 78 103 } 104 105 # Loop through contents of %loc_hash, check for existence within @searchresults, and add as necessary 106 107 foreach my $key (keys %loc_hash) 108 { 109 my $resultline = $key."::".$loc_hash{$key}; 110 111 if (! grep(/^$key/, @searchresults)) 112 { 113 push (@searchresults, $resultline); 114 } 115 } 79 116 80 117 return @searchresults; 81 118 }