Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Drop the BBC weather grabber, it's broken and replaced by the Met Off…

…ice grabber in the UK, Wunderground for the rest of the world
  • Loading branch information...
commit 2af21560c7ba4f219b79403e11e79c14ebbf90ca 1 parent f66816d
@stuartm stuartm authored
View
2  mythplugins/mythweather/mythweather/scripts/Makefile
@@ -1,6 +1,6 @@
include ../../../mythconfig.mak
-SUBDIRS = ca_envcan no_yrno uk_bbc uk_metoffice us_nws wunderground
+SUBDIRS = ca_envcan no_yrno uk_metoffice us_nws wunderground
# Do not change anything below this line unless you really know what you are
# doing.
View
210 mythplugins/mythweather/mythweather/scripts/uk_bbc/BBCLocation.pm
@@ -1,210 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=4:sw=4:ai:et:si:sts=4
-
-package BBCLocation;
-use strict;
-use warnings;
-require Exporter;
-
-use utf8;
-use encoding 'utf8';
-use LWP::UserAgent;
-use JSON;
-use XML::XPath;
-use XML::XPath::XMLParser;
-use URI::Escape;
-
-
-our @EXPORT = qw(Search FindLoc);
-our $VERSION = 0.3;
-
-my @searchresults;
-my @resulturl;
-my $resultcount = -1;
-
-sub Search {
- my ($search_string, $dir, $timeout, $logdir) = @_;
- $search_string = uri_escape($search_string);
-
- my $base_url = 'http://www.bbc.co.uk/locator/client/weather/en-GB/' .
- 'search.json';
- my $search_url = $base_url . '?ptrt=/&search=';
-
-
- my $file = $search_string;
- getCachedJSON($search_url . $search_string, $dir, $file, $timeout, $logdir);
-
- my $cachefile = "$dir/$file.json";
- my $cachefile1 = "$dir/$file-results.html";
- my $cachefile2 = "$dir/$file-pagination.html";
-
- open OF, "<:utf8", $cachefile or die "Can't read $cachefile: $!\n";
- my $content = do { local $/; <OF> };
- close OF;
-
- my $decoded = decode_json $content;
- $resultcount = $decoded->{"noOfResults"};
-
- my %loc_hash = ();
-
- get_results($cachefile1, \%loc_hash);
-
- if (exists $decoded->{"pagination"}) {
- my %pages = ();
- my $xp = XML::XPath->new(filename => $cachefile2);
- my $nodeset = $xp->find("//ol/li/a");
- foreach my $node ($nodeset->get_nodelist) {
- my $url = $node->getAttribute("href");
- my $num = $node->string_value;
- $url =~ s/&amp;/&/;
- $num =~ s/ //g;
- $pages{$num} = $url;
- }
-
- foreach my $page (keys %pages)
- {
- getCachedJSON($base_url . $pages{$page}, $dir, $file . "-$page",
- $timeout, $logdir);
-
- my $cachefile3 = "$dir/$file-$page-results.html";
- get_results($cachefile3, \%loc_hash);
- }
- }
-
- my @searchresults = ();
- foreach my $key (keys %loc_hash)
- {
- my $resultline = $key."::".$loc_hash{$key};
- push (@searchresults, $resultline);
- }
- return @searchresults;
-}
-
-sub getCachedJSON {
- my ($url, $dir, $file, $timeout, $logdir) = @_;
-
- my $cachefile = "$dir/$file.json";
- my $cachefile1 = "$dir/$file-results.html";
- my $cachefile2 = "$dir/$file-pagination.html";
-
- my $now = time();
- my $decoded;
-
- log_print( $logdir, "Loading URL: $url\n" );
-
- if( (-e $cachefile) and ((stat($cachefile))[9] >= ($now - $timeout)) ) {
- # File cache is still recent.
- log_print( $logdir, "cached in $cachefile\n" );
- } else {
- log_print( $logdir, "$url\ncaching to $cachefile\n" );
-
- my $ua = LWP::UserAgent->new;
- $ua->timeout(30);
- $ua->env_proxy;
- $ua->default_header('Accept-Language' => "en");
-
- my $response = $ua->get($url);
- if ( !$response->is_success ) {
- die $response->status_line;
- }
-
- open OF, ">:utf8", $cachefile or die "Can't open $cachefile: $!\n";
- print OF $response->content;
- close OF;
-
- $decoded = decode_json $response->content;
-
- open OF, ">:utf8", $cachefile1 or die "Can't open $cachefile1: $!\n";
- print OF "<html>".$decoded->{"results"}."</html>";
- close OF;
-
- if (exists $decoded->{"pagination"}) {
- open OF, ">:utf8", $cachefile2 or
- die "Can't open $cachefile2: $!\n";
- print OF "<html>".$decoded->{"pagination"}."</html>";
- close OF;
- } else {
- unlink $cachefile2;
- }
- }
-}
-
-sub get_results {
- my ($file, $outhash) = @_;
-
- my $xp = XML::XPath->new(filename => $file);
- my $nodeset = $xp->find("//ul/li/a");
- foreach my $node ($nodeset->get_nodelist) {
- my $url = $node->getAttribute("href");
- my $loc = $node->string_value;
-
- $url =~ s/^\/weather\///;
- $outhash->{$url} = $loc;
- }
-}
-
-sub log_print {
- return if not defined $::opt_D;
- my $dir = shift;
-
- open OF, ">>$dir/uk_bbc.log";
- print OF @_;
- close OF;
-}
-
-sub FindLoc {
- my ($locid, $dir, $timeout, $logdir) = @_;
-
- my $url = "http://www.bbc.co.uk/weather/$locid";
-
- my $file = "$locid.html";
- getCachedHTML($url, $dir, $file, $timeout, $logdir);
-
- my $cachefile = "$dir/$file";
-
- open OF, "<:utf8", $cachefile;
- my $contents = do { local $/; <OF>; };
- close OF;
-
- my ($rssid) = ($contents =~ /data-loc="(.*?)"/);
- die "No RSS Location found for ID $locid!\n" unless defined $rssid;
-
- $rssid =~ s/^LOC-//;
- return $rssid;
-}
-
-
-sub getCachedHTML {
- my ($url, $dir, $file, $timeout, $logdir) = @_;
-
- my $cachefile = "$dir/$file";
-
- my $now = time();
-
- log_print( $logdir, "Loading URL: $url\n" );
-
- if( (-e $cachefile) and ((stat($cachefile))[9] >= ($now - $timeout)) ) {
- # File cache is still recent.
- log_print( $logdir, "cached in $cachefile\n" );
- } else {
- log_print( $logdir, "$url\ncaching to $cachefile\n" );
-
- my $ua = LWP::UserAgent->new;
- $ua->timeout(30);
- $ua->env_proxy;
- $ua->default_header('Accept-Language' => "en");
-
- my $response = $ua->get($url);
- if ( !$response->is_success ) {
- die $response->status_line;
- }
-
- my $content = $response->content;
- open OF, ">:utf8", $cachefile or die "Can't open $cachefile: $!\n";
- print OF $content;
- close OF;
- }
-}
-
-
-1;
View
5 mythplugins/mythweather/mythweather/scripts/uk_bbc/Makefile
@@ -1,5 +0,0 @@
-DATA = BBCLocation.pm
-SCRIPTS = bbccurrentxml.pl bbcthreedayxml.pl
-
-include ../Makefile.inc
-
View
269 mythplugins/mythweather/mythweather/scripts/uk_bbc/bbccurrentxml.pl
@@ -1,269 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=4:sw=4:ai:et:si:sts=4
-
-use strict;
-use warnings;
-
-use utf8;
-use encoding 'utf8';
-use English;
-
-use File::Basename;
-use Cwd 'abs_path';
-use lib dirname(abs_path($0 or $PROGRAM_NAME)),
- '/usr/share/mythtv/mythweather/scripts/uk_bbc',
- '/usr/local/share/mythtv/mythweather/scripts/uk_bbc';
-
-use XML::Simple;
-use LWP::Simple;
-use Getopt::Std;
-use File::Path;
-
-use File::Basename;
-use lib dirname($0);
-use BBCLocation;
-
-our ($opt_v, $opt_t, $opt_T, $opt_l, $opt_u, $opt_d, $opt_D);
-
-my $name = 'BBC-Current-XML';
-my $version = 0.5;
-my $author = 'Gavin Hurlbut / Stuart Morgan';
-my $email = 'gjhurlbu@gmail.com / stuart@tase.co.uk';
-my $updateTimeout = 120*60;
-# 2 Hours, BBC updates infrequently ~3 hours
-my $retrieveTimeout = 30;
-my @types = ('cclocation', 'station_id', 'copyright', 'copyrightlogo',
- 'observation_time', 'weather', 'temp', 'relative_humidity',
- 'wind_dir', 'pressure', 'visibility', 'weather_icon',
- 'appt', 'wind_spdgst');
-my $dir = "/tmp/uk_bbc";
-my $logdir = "/tmp/uk_bbc";
-
-binmode(STDOUT, ":utf8");
-
-if (!-d $logdir) {
- mkpath( $logdir, {mode => 0755} );
-}
-
-getopts('Tvtlu:d:');
-
-if (defined $opt_v) {
- print "$name,$version,$author,$email\n";
- log_print( $logdir, "-v\n" );
- exit 0;
-}
-
-if (defined $opt_T) {
- print "$updateTimeout,$retrieveTimeout\n";
- log_print( $logdir, "-t\n" );
- exit 0;
-}
-
-if (defined $opt_d) {
- $dir = $opt_d;
-}
-
-if (!-d $dir) {
- mkpath( $dir, {mode => 0755} );
-}
-
-if (defined $opt_l) {
- my $search = shift;
- log_print( $logdir, "-l $search\n" );
- my @results = BBCLocation::Search($search, $dir, $updateTimeout, $logdir);
- my $result;
-
- foreach (@results) {
- print $_ . "\n";
- }
-
- exit 0;
-}
-
-if (defined $opt_t) {
- foreach (@types) {print; print "\n";}
- exit 0;
-}
-
-
-# we get here, we're doing an actual retrieval, everything must be defined
-my $locid = BBCLocation::FindLoc(shift, $dir, $updateTimeout, $logdir);
-if (!(defined $opt_u && defined $locid && !$locid eq "")) {
- die "Invalid usage";
-}
-
-my $units = $opt_u;
-my $base_url = 'http://newsrss.bbc.co.uk/weather/forecast/';
-my $base_xml = '/ObservationsRSS.xml';
-
-if ($locid =~ s/^(\d*)/$1/)
-{
- $base_url = $base_url . $1 .$base_xml;
-}
-else
-{
- die "Invalid Location ID";
-}
-
-my $response = get $base_url;
-die unless defined $response;
-
-my $xml = XMLin($response);
-
-if (!$xml) {
- die "Not xml";
-}
-
-# The required elements which aren't provided by this feed
-print "appt::NA\n";
-print "copyright::bbc.co.uk - ©2012 BBC\n";
-print "copyrightlogo::none\n";
-print "station_id::" . $locid . "\n";
-my $location = $xml->{channel}->{title};
-$location =~ s/.*?Observations for (.*)$/$1/s;
-print "cclocation::" . $location . "\n";
-
-my $item_title = $xml->{channel}->{item}->{title};
-
-my $obs_time = $1 if ($item_title =~ /(^.*)\:.*/);
-printf "observation_time::" . $obs_time . "\n";
-my $weather_string = $item_title;
-
-$weather_string =~ s/.*\:.*\n(.*)\..*/$1/s;
-$weather_string = ucfirst($weather_string);
-printf "weather::" . $weather_string . "\n";
-
-if ($weather_string =~ /^cloudy$/i ||
- $weather_string =~ /^grey cloud$/i ||
- $weather_string =~ /^white cloud$/i) {
- printf "weather_icon::cloudy.png\n";
-}
-elsif ($weather_string =~ /^fog$/i ||
- $weather_string =~ /^foggy$/i ||
- $weather_string =~ /^mist$/i ||
- $weather_string =~ /^misty$/i) {
- printf "weather_icon::fog.png\n";
-}
-elsif ($weather_string =~ /^sunny$/i) {
- printf "weather_icon::sunny.png\n";
-}
-elsif ($weather_string =~ /^sunny intervals$/i ||
- $weather_string =~ /^partly cloudy$/i) {
- printf "weather_icon::pcloudy.png\n";
-}
-elsif ($weather_string =~ /^drizzle$/i ||
- $weather_string =~ /^light rain$/i ||
- $weather_string =~ /^light rain showers?$/i ||
- $weather_string =~ /^light showers?$/i) {
- printf "weather_icon::lshowers.png\n";
-}
-elsif ($weather_string =~ /^heavy rain$/i ||
- $weather_string =~ /^heavy showers?$/i ||
- $weather_string =~ /^heavy rain showers?$/i) {
- printf "weather_icon::showers.png\n";
-}
-elsif ($weather_string =~ /^thundery rain$/i ||
- $weather_string =~ /^thunder storm$/i ||
- $weather_string =~ /^thundery showers?$/i) {
- printf "weather_icon::thunshowers.png\n";
-}
-elsif ($weather_string =~ /^heavy snow$/i) {
- printf "weather_icon::snowshow.png\n";
-}
-elsif ($weather_string =~ /^light snow$/i ||
- $weather_string =~ /^light snow showers?$/i) {
- printf "weather_icon::flurries.png\n";
-}
-elsif ($weather_string =~ /^sleet$/i ||
- $weather_string =~ /^sleet showers?$/i ||
- $weather_string =~ /^hail showers?$/i) {
- printf "weather_icon::rainsnow.png\n";
-}
-elsif ($weather_string =~ /^clear$/i ||
- $weather_string =~ /^clear sky$/i) {
- printf "weather_icon::fair.png\n";
-}
-else {
- printf "weather_icon::unknown.png\n";
-}
-
-my @data = split(/, /, $xml->{channel}->{item}->{description});
-foreach (@data) {
- my $datalabel;
- my $datavalue;
-
- ($datalabel, $datavalue) = split(': ', $_);
- if ($datalabel =~ /Temperature/) {
- if ($units =~ /ENG/) {
- $datavalue =~ s/^.*?\((-?\d{1,2}).*/$1/;
- }
- elsif ($units =~ /SI/) {
- $datavalue =~ s/^(-?\d{1,2}).*/$1/;
- }
- $datalabel = "temp";
- }
- elsif ($datalabel =~ /Wind Direction/) {
- $datalabel = "wind_dir";
- }
- elsif ($datalabel =~ /Wind Speed/) {
- $datalabel = "wind_spdgst";
- $datavalue =~ s/^(\d{1,3})mph.*/$1/;
-
- if ($units =~ /SI/) {
- $datavalue = int($datavalue * 1.609344 + .5);
- }
-
- $datavalue = $datavalue . " (NA)";
- }
- elsif ($datalabel =~ /Relative Humidity/) {
- $datalabel = "relative_humidity";
- $datavalue =~ s/^(\d{1,3})%.*?/$1/;
- }
- elsif ($datalabel =~ /Pressure/) {
- $datavalue =~ s/^(\d*)mB.*?/$1/;
-
- if ($units =~ /ENG/) {
- $datavalue = $datavalue * 0.0295301 + .5;
- }
-
- $datalabel = "pressure";
- }
- elsif ($datalabel =~ /Visibility/) {
- $datalabel = "visibility";
- if ($datavalue =~ /^Very Poor/i) {
- $datavalue = "< 1";
- }
- elsif ($datavalue =~ /^Poor/i) {
- $datavalue = "1-4";
- }
- elsif ($datavalue =~ /^Moderate/i) {
- $datavalue = "4-10";
- }
- elsif ($datavalue =~ /^Good/i) {
- $datavalue = "10-20";
- }
- elsif ($datavalue =~ /^Very Good/i) {
- $datavalue = "20-40";
- }
- elsif ($datavalue =~ /^Excellent/i) {
- $datavalue = "40+";
- }
- else {
- $datavalue = "?";
- }
- }
- else {
- next;
- }
-
- printf $datalabel . "::" . $datavalue . "\n";
-}
-
-sub log_print {
- return if not defined $::opt_D;
- my $dir = shift;
-
- open OF, ">>$dir/uk_bbc.log";
- print OF @_;
- close OF;
-}
View
257 mythplugins/mythweather/mythweather/scripts/uk_bbc/bbcthreedayxml.pl
@@ -1,257 +0,0 @@
-#! /usr/bin/perl
-# vim:ts=4:sw=4:ai:et:si:sts=4
-
-use strict;
-use warnings;
-
-use utf8;
-use encoding 'utf8';
-use English;
-
-use File::Basename;
-use Cwd 'abs_path';
-use lib dirname(abs_path($0 or $PROGRAM_NAME)),
- '/usr/share/mythtv/mythweather/scripts/uk_bbc',
- '/usr/local/share/mythtv/mythweather/scripts/uk_bbc';
-
-use XML::Simple;
-use LWP::Simple;
-use Getopt::Std;
-use File::Path;
-
-use File::Basename;
-use lib dirname($0);
-use BBCLocation;
-
-our ($opt_v, $opt_t, $opt_T, $opt_l, $opt_u, $opt_d, $opt_D);
-
-my $name = 'BBC-3day-XML';
-my $version = 0.5;
-my $author = 'Gavin Hurlbut / Stuart Morgan';
-my $email = 'gjhurlbu@gmail.com / stuart@tase.co.uk';
-my $updateTimeout = 360*60; # 6 Hours
-my $retrieveTimeout = 30;
-my @types = ('3dlocation', 'station_id', 'copyright', 'copyrightlogo',
- 'weather_icon',
- 'date-0', 'icon-0', 'low-0', 'high-0',
- 'date-1', 'icon-1', 'low-1', 'high-1',
- 'date-2', 'icon-2', 'low-2', 'high-2', 'updatetime');
-my $dir = "/tmp/uk_bbc";
-my $logdir = "/tmp/uk_bbc";
-
-binmode(STDOUT, ":utf8");
-
-if (!-d $logdir) {
- mkpath( $logdir, {mode => 0755} );
-}
-
-getopts('Tvtlu:d:');
-
-if (defined $opt_v) {
- print "$name,$version,$author,$email\n";
- log_print( $logdir, "-v\n" );
- exit 0;
-}
-
-if (defined $opt_T) {
- print "$updateTimeout,$retrieveTimeout\n";
- log_print( $logdir, "-t\n" );
- exit 0;
-}
-
-if (defined $opt_d) {
- $dir = $opt_d;
-}
-
-if (!-d $dir) {
- mkpath( $dir, {mode => 0755} );
-}
-
-if (defined $opt_l) {
- my $search = shift;
- log_print( $logdir, "-l $search\n" );
- my @results = BBCLocation::Search($search, $dir, $updateTimeout, $logdir);
- my $result;
-
- foreach (@results) {
- print $_ . "\n";
- }
-
- exit 0;
-}
-
-if (defined $opt_t) {
- foreach (@types) {print; print "\n";}
- exit 0;
-}
-
-
-# we get here, we're doing an actual retrieval, everything must be defined
-my $locid = BBCLocation::FindLoc(shift, $dir, $updateTimeout, $logdir);
-if (!(defined $opt_u && defined $locid && !$locid eq "")) {
- die "Invalid usage";
-}
-
-my $units = $opt_u;
-my $base_url = 'http://newsrss.bbc.co.uk/weather/forecast/';
-my $base_xml = '/Next3DaysRSS.xml';
-
-if ($locid =~ s/^(\d*)/$1/)
-{
- $base_url = $base_url . $1 . $base_xml;
-}
-else
-{
- die "Invalid Location ID";
-}
-
-
-my $response = get $base_url;
-die unless defined $response;
-
-my $xml = XMLin($response);
-
-if (!$xml) {
- die "Not xml";
-}
-
-print "copyright::bbc.co.uk - ©2012 BBC\n";
-print "copyrightlogo::none\n";
-print "station_id::" . $locid . "\n";
-my $location = $xml->{channel}->{title};
-$location =~ s/.*?Forecast for (.*)$/$1/s;
-print "3dlocation::" . $location . "\n";
-print "updatetime::Updated " . localtime() . "\n";
-
-my $i = 0;
-my $item;
-
-foreach $item (@{$xml->{channel}->{item}}) {
-
- my $item_title = $item->{title};
- $item_title =~ s/\n//;
-
- my $day = $item_title;
- $day =~ s/^(.*?):.*/$1/;
-
- if ($day eq 'Sunday') {
- $day = '0';
- }
- elsif ($day eq 'Monday') {
- $day = '1';
- }
- elsif ($day eq 'Tuesday') {
- $day = '2';
- }
- elsif ($day eq 'Wednesday') {
- $day = '3';
- }
- elsif ($day eq 'Thursday') {
- $day = '4';
- }
- elsif ($day eq 'Friday') {
- $day = '5';
- }
- elsif ($day eq 'Saturday') {
- $day = '6';
- }
-
- printf "date-" . $i . "::" . $day . "\n";
-
- my $weather_string = $item_title;
- $weather_string =~ s/.*?\: (.*?),.*/$1/s;
- $weather_string = ucfirst($weather_string);
-
- if ($weather_string =~ /^cloudy$/i ||
- $weather_string =~ /^grey cloud$/i ||
- $weather_string =~ /^white cloud$/i) {
- printf "icon-" . $i . "::cloudy.png\n";
- }
- elsif ($weather_string =~ /^fog$/i ||
- $weather_string =~ /^foggy$/i ||
- $weather_string =~ /^mist$/i ||
- $weather_string =~ /^misty$/i) {
- printf "icon-" . $i . "::fog.png\n";
- }
- elsif ($weather_string =~ /^sunny$/i) {
- printf "icon-" . $i . "::sunny.png\n";
- }
- elsif ($weather_string =~ /^sunny intervals$/i ||
- $weather_string =~ /^partly cloudy$/i) {
- printf "icon-" . $i . "::pcloudy.png\n";
- }
- elsif ($weather_string =~ /^drizzle$/i ||
- $weather_string =~ /^light rain$/i ||
- $weather_string =~ /^light rain showers?$/i ||
- $weather_string =~ /^light showers?$/i) {
- printf "icon-" . $i . "::lshowers.png\n";
- }
- elsif ($weather_string =~ /^heavy rain$/i ||
- $weather_string =~ /^heavy showers?$/i ||
- $weather_string =~ /^heavy rain showers?$/i) {
- printf "icon-" . $i . "::showers.png\n";
- }
- elsif ($weather_string =~ /^thundery rain$/i ||
- $weather_string =~ /^thunder storm$/i ||
- $weather_string =~ /^thundery showers?$/i) {
- printf "icon-" . $i . "::thunshowers.png\n";
- }
- elsif ($weather_string =~ /^heavy snow$/i) {
- printf "icon-" . $i . "::snowshow.png\n";
- }
- elsif ($weather_string =~ /^light snow$/i ||
- $weather_string =~ /^light snow showers?$/i) {
- printf "icon-" . $i . "::flurries.png\n";
- }
- elsif ($weather_string =~ /^sleet$/i ||
- $weather_string =~ /^sleet showers?$/i ||
- $weather_string =~ /^hail showers?$/i) {
- printf "icon-" . $i . "::rainsnow.png\n";
- }
- elsif ($weather_string =~ /^clear$/i ||
- $weather_string =~ /^clear sky$/i) {
- printf "icon-" . $i . "::fair.png\n";
- }
- else {
- printf "icon-" . $i . "::unknown.png\n";
- }
-
- my @data = split(/, /, $item->{description});
- foreach (@data) {
- my $datalabel;
- my $datavalue;
-
- ($datalabel, $datavalue) = split(': ', $_);
- if ($datalabel =~ /.*Temp$/) {
- if ($units =~ /ENG/) {
- $datavalue =~ s/^.*?\((-?\d{1,2}).*/$1/;
- }
- elsif ($units =~ /SI/) {
- $datavalue =~ s/^(-?\d{1,2}).*/$1/;
- }
- if ($datalabel =~ /^Max.*/) {
- $datalabel = "high-" . $i;
- }
- elsif ($datalabel =~ /^Min.*/) {
- $datalabel = "low-" . $i;
- }
-
- }
- else {
- next;
- }
-
- printf $datalabel . "::" . $datavalue . "\n";
- }
-
- $i++;
-}
-
-sub log_print {
- return if not defined $::opt_D;
- my $dir = shift;
-
- open OF, ">>$dir/uk_bbc.log";
- print OF @_;
- close OF;
-}
Please sign in to comment.
Something went wrong with that request. Please try again.