Saturday, September 22, 2007

Batteries included

I used to read a few news feeds in Thunderbird, it worked pretty nice (except that things got badly corrupted if disk got full). However I started working from different computers to a larger extent, so I wanted to maintain state across computers so articles I have read are marked as such on all computers I use. I did actually consider using some online service such as google reader, but I realized that I want more control and it would be nice to be able to read stuff offline.

So I decided I wanted to store them to maildirs accessible over imap. I found quite a few different tools to get feeds converted into email in different formats. Newspipe looked most promising, so I set it up to pipe to procmail using a special procmail.rc-file. But things didn't really behave they way I wanted. It also wanted to run in daemon mode, I would have preferred it to run from cron.

Well, how hard can it be to write a pythonscript that grabs feeds and stores into maildirs, I thought. I had heard about feedparser, it was supposed to be good. apt-get install python-feedparser. Firing up the python interactive console poking around a bit with feedparser, grabbing rss/atom feeds was indeed a walk in the park. I recall having seen something about maildir support in python somewhere. Yes, google tells me there is a maildir module shipped with python. Batteries included. But at first the documentation didn't seem correct, it mentioned stuff that wasn't available in the module on my system. Oh, it had been updated for Python2.5, I finally got to write my first real python2.5 script (yet I didn't manage to squeeze in a with-operator or usage of the new generator features). I had to maintain state across invocations, so throw in another standard module, pickle and feeddir was born.

So now I have feeddir.py update in cron. And can do feeddir.py add feeds.xmms2planet http://planet.xmms.se/rss20.xml to add a new feed which will be available for subscription in my imap clients (unders feeds/xmms2planet).

Code can be found here.

Labels: , , ,

0 Comments:

Post a Comment

<< Home