The code that fixes the Sybase Tech Talk podcast

Yeah, I know it isn’t pretty but it works. 

#!/usr/bin/perl
use strict;
use warnings;
use Net::FTP;
use XML::RSS;
use LWP::Simple;
use CGI::Util qw(unescape escape);
sub clean_str {

#!/usr/bin/perl
use strict;
use warnings;
use Net::FTP;
use XML::RSS;
use LWP::Simple;
use CGI::Util qw(unescape escape);
sub clean_str {
        # there is a bunch of garbage in the descriptions in the sybase rss file
        my $str = shift;
        $str =~ s/\%C2\%96 //g;
        $str = unescape($str);
        return $str;
}
my $rss = XML::RSS->new;
my $new_rss = XML::RSS->new (version => ’2.0′, encoding => ‘ISO-8859-1′);
my $content = get( "http://www.sybase.com/detailList/rss.do?nodeId=113048" );
eval { $rss->parse($content) };
if ($@) {
        die "Bad XML document!!\n";
} else {
        $new_rss->channel(
                title           => clean_str( $rss->channel(‘title’) ),
                link            => $rss->channel(‘link’),
                description     => clean_str( $rss->channel(‘description’) ),
                language        => $rss->channel(‘language’)
        );
        foreach my $item ( @{$rss->{‘items’}} ) {
                $new_rss->add_item(
                        title           => clean_str( $item->{‘title’} ),
                        enclosure       => { url => $item->{‘link’}, type => "audio/mpeg" },
                        description     => clean_str( $item->{‘description’} ),
                        pubDate         => $item->{‘pubDate’}
                );
        }
        $new_rss->save("/home/jason/ftp/sybase_ase_tech_talk.rss");
        my $ftp = Net::FTP->new("ftp.somewhere.com", Debug => 0)
                or die "Cannot connect to ftp.somewhere.com: $@";
        $ftp->login(‘my_login’,'mypassword’)
                or die "Cannot login ", $ftp->message;
        $ftp->cwd("rss")
                or die "Unable to change directory to /rss", $ftp->message;
        $ftp->put("/home/jason/ftp/sybase_ase_tech_talk.rss")
                or die "Cannot upload ase_tech_talk.rss", $ftp->message;
        $ftp->quit;
}

Leave a Reply

Your email address will not be published. Required fields are marked *