Well here is a simple way to put it into a Tk marquee.
UPDATESet timer to update every 5 minutes.
#!/usr/bin/perl
#click on marquee to remove
use strict;
use LWP::Simple;
use Tk;
my $text;
my $mw = tkinit;
$mw->geometry('+20+20');
$mw->overrideredirect(1);
my $label = $mw->Label(
-textvariable=>\$text,
-font=>'courier',
-bg=>'green',
-bd=>4,
-relief=>'ridge'
)->pack(-fill=>'both');
getnews();
$mw->repeat(300000,\&getnews);
$label->bind('<ButtonRelease>',sub{$mw->destroy});
$mw->repeat(160,[sub{$text=~s/(.)(.*)/$2$1/;}]);
MainLoop;
#####################################################
sub getnews{
my %ticker = parse_ticker_data(
'http://tickers.bbc.co.uk/tickerdata/story2.dat'
);
my @stories;
foreach my $story (@{ $ticker{'WORLD'} }) {
push @stories, $story->{headline}
}
$text = join ' - ', @stories;
$label->update;
return;
}
######################################################################
+###
sub parse_ticker_data {
my $ticker_data_url = $_[0];
my (%ticker, $current_category, @stories_in_this_cat, $last_category
+,
$last_token, $headline, $url);
die "No ticker URL supplied to parse_ticker_data()" if (!$ticker_dat
+a_url);
# Download the ticker data file from the BBC
my $ticker_data = get $ticker_data_url;
die "Couldn't retrive ticker data" if (!$ticker_data);
#for offline testing
#open (FILE,"<story2.dat") or die "Couldn't open: $!";
#my $ticker_data = do {local $/; <FILE>};
#close FILE;
# Examine each line in the ticker data file
foreach (split /\n/, $ticker_data) {
if (/Last update at (\d\d:\d\d)/) { # Extract last updated time
$ticker{update_time} = $1 . ' GMT';
$headline = undef;
next;
}
# Set the current category
if (/HEADLINE\s
(SPORTS|BUSINESS|WORLD|UK|SCI-TECH|TRAVEL|WEATHER|FINANCE)/x) {
$current_category = $1;
$last_token = 'new';
$headline = undef;
next;
}
my ($token, @data) = split /\s/, $_;
my $data = join ' ', @data;
# Have we changed categories? If so, then we need to store all the
+
# stories in the old category in the data structure
if ($current_category ne $last_category) {
if (@stories_in_this_cat) {
my @narrow_scoped = @stories_in_this_cat;
$ticker{$last_category} = \@narrow_scoped;
@stories_in_this_cat = ();
}
}
if ( ($token eq 'HEADLINE') and ($last_token eq 'STORY') ) {
# Starting to parse a new headline. Need to put the old one onto
+
# the array though.
if ($headline) { # don't want headlines like "UK News", see ab
+ove
push @stories_in_this_cat,
{ headline => $headline, url => $url };
}
$headline = $data;
}
# Set the URL
if ($token eq 'URL') {
$url = $data;
}
# Update for next iteration
$last_token = $token;
$last_category = $current_category;
}
# The last category won't be added in the loop, so need to do it
# manually. This is nasty, so any improvements would be welcome :-)
+
$ticker{$current_category} = \@stories_in_this_cat;
return %ticker;
}
##################################################################
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.