Hak5
Save 10% at GoDaddy.com with coupon code HAK

Talk:RSS Alarm Clock Under Linux

From Hak5

Jump to: navigation, search

A couple quick notes:

1) In the original step two (2), the perl modules may be installed on Ubuntu by using:

  • sudo apt-get install libxml-rss-perl libwww-perl

2) I made a slight modification to the weather.pl script to 1) remove some extraneous code apparently left over from the original, and 2) to add a subroutine to allow the conversion of abbreviations to plain language, e.g. mph to miles per hour. This allows festival to better pronounce the text.

#!/usr/bin/perl -w
# rss2html - converts an RSS file to HTML
# It take one argument, either a file on the local system,
# or an HTTP URL like http://slashdot.org/slashdot.rdf
# by Jonathan Eisenzopf. v1.0 19990901
# Copyright (c) 1999 Jupitermedia Corp. All Rights Reserved.
# See http://www.webreference.com/perl for more information
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.


#  ~~~P1mped 0ut l33t hax0r s7yle by d1gital~~~
#  ~~~ Additional Slight Modifications by Vyper ~~~

# INCLUDES
use strict;
use XML::RSS;
use LWP::Simple;

# Declare variables
my $content;
my $file;

# MAIN
# check for command-line argument
die "Usage: weather.pl <zipcode> \n" unless @ARGV == 1;

# get the command-line argument
my $arg = shift;

# create new instance of XML::RSS
my $rss = new XML::RSS;

my $url = "http://www.rssweather.com/zipcode/$arg/rss.php";
    $content = get($url);
    die "Could not retrieve $url" unless $content;
    # parse the RSS content
    $rss->parse($content);

# print the HTML channel
&print_html($rss);

# SUBROUTINES
#
sub elucidate {
    $_ = shift;
    s/mph/miles per hour/g;
    s/(\d+)F/$1 degrees Fahrenheit/g;
    return $_;
}

sub print_html {
    my $rss = shift;

    # print the channel items
    for (1..2) 
    {
      my $item = shift(@{$rss->{'items'}});
      next unless defined($item->{'description'});
      print elucidate($item->{'description'});
      print "... ... ... ... ...\n";
    }
}

--Vyper 08:23, 12 November 2006 (PST)