Microwave Biscuit

Sylpheed-claws RSS Plugin and Perl Script

Posted in Linux, ubuntu by microwavebiscuit on March 21, 2007

Sylpheed-claws has a really nice RSS Plugin available. I installed it immediately and added a couple of feeds to it. Now I have RSS embedded in my mail client so I can view some feeds almost as if they were mail messages. The only real drawback is if you regularly get feeds with lots of images, etc attached as they get stripped out. In any case, after configuring a few mail feeds manually, I thought it would be nice if I could import the feeds in someway. I went to Liferea and exported my feeds as an OPML file. It’s basically just XML and Perl has some easy ways to parse it. Should be a piece of cake, right?

First step is to figure out how to parse the opml file. I accomplished it by using the Perl Module XML::Simple. I found a few examples online using XML::Simple and I was able to hack together a script. I was able to first pump out the feed name and url to the console then continued tweaking to write it to a file. The RSS Plugin also uses an XML file to store the feed list so I figured, parse the OPML file and then pump it out to a new xml file to use. After much testing, I got it to work as I wanted. So, I closed Sylpheed, run my script which replaced the existing file with my newly created one. Reopened Sylpheed but I didn’t have my new feeds!

Second step – I realized that for each feed you add, Sylpheed creates a folder under the RSS plugin directory. So, I figured, why not create the folders required as part of the perl script! Not too hard, and I managed to get that to happen. Close Sylpheed, run the script, reopen Sylpheed and still no luck. I did a little more digging and it turns out that in order to get the folders to appear, I’ll have to modify yet another configuration file! There’s a file called folderlist.xml which I think I need to append some stuff to in order to get it to work. I haven’t got that part done yet but I’m working on it.

I also realize that in the time I’ve spent working on this script I could have added in all of my feeds manually, but since I started down this path I’d like to bring it to completion just so I can say I did it. Of course if I get it to work, I’ll share the code so that others can easily import feeds into the RSS Plugin.

Here’s the code I have so far. It’s not pretty but it does do exactly what I want it to. I still have more development to do and I may clean it up some too.

Contents:

#!/usr/bin/perl
use strict;
use warnings;
use XML::Simple;
use Data::Dumper;
# create object
my $xml = new XML::Simple (KeyAttr=>[]);
# read XML file
my $data = $xml->XMLin("/home/me/feedlist.opml"); #read exported opml file
chdir($ENV{HOME} . "/.sylpheed-claws/RSSyl/") || die("Can't find your .claws-mail directory\n");
open(TEMPFL, '>/home/me/feeds.xml') or die "$0: Cannot open file for output!\n"; #open output file
select TEMPFL;
print '', "\n";
print "\n";
my $e;
foreach $e (@{$data->{body}->{outline}->{outline}})
{
print "{title}, '"', " official_name=", '"', $e->{title}, '"', " url=", '"', $e->{xmlUrl}, '"', ' default_refresh_interval="1" default_expired_num="1" fetch_comments="0"/>',"\n";
mkdir $e->{title}, 0777 || die "Can't make required directory";
}
print "\n";
close TEMPFL;

Advertisements

3 Responses

Subscribe to comments with RSS.

  1. Paul said, on March 28, 2007 at 11:19 pm

    When you’ve cleaned up this script I would be happy to include it in the Claws Mail tools/ dir, (as long as it is GPL licensed).

    There are a few scripts there that will give you a few shortcuts for some operations, e.g. finding the user’s Claws config dir. For example, tools/filter_conv_new.pl.

  2. cycojesus said, on August 14, 2007 at 5:01 am

    Here’s the shell version 😉 :

    #!/bin/sh

    echo “”
    echo “”

    grep -o “title=\”.*\”” -o “xmlUrl=\”http://.*\”” $1 \
    | sed ‘s/title=//g’ \
    | sed ‘s/xmlUrl=//g’ \
    | awk -F “\”” ‘{printf ” \n”, $2, $2, $12}’

    echo “”

  3. cycojesus said, on August 14, 2007 at 5:02 am

    #!/bin/sh

    echo “[?xml version=\”1.0\”?]”
    echo “[feeds]”

    grep -o “title=\”.*\”” -o “xmlUrl=\”http://.*\”” $1 \
    | sed ‘s/title=//g’ \
    | sed ‘s/xmlUrl=//g’ \
    | awk -F “\”” ‘{printf ” [feed name=\”%s\” official_name=\”%s\” url=\”%s\” default_refresh_interval=\”1\” default_expired_num=\”1\” fetch_comments=\”0\”/]\n”, $2, $2, $12}’

    echo “[/feeds]”

    ( [ are …)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: