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: , , ,

Friday, September 07, 2007

Playlist language

This code has been sitting in my homedir for quite a while, finally got around to clean it up enough to publish it. There still is way too many rough edges, but the implementation isn't very interesting anyway.

I wanted a readable language for custom playlist formatting, instead of some hard to read string like: $if(%album artist%,%album%,%artist%)|$if(%album artist%,$num(%tracknumber%,2) - %title%,%album%)|$if($not(%album artist%),$num(%tracknumber%,2) - %title%)

Playlists are pretty much rows of data, which should be processed one by one, doing different things depending on what they contain. So lets have a language that has the form list(predicate + list(actions)), a bit like awk. There is no need to have multiple levels of nesting, so making use of indentation should be simple, a bit like python.

So, without further delay, here is an example in the playlist language where awk meets python:

:title && :artist == lastartist
pad(lastartist)
emit(" + ")
emit(:title)
emit(CR)
done()

:title && :artist
emit()
emit(:artist)
emit(" - ")
emit(:title)
set(lastartist, :artist)
emit(CR)
done()

"always"
set(lastartist, "")
emit(:url)
emit(CR)


...and here is the (crappy) implementation. There is no loops and things to avoid the halting problem.



BTW. I put the cunit-wrapper in git aswell, and added an example that is a 1:1 conversion of the cunit example.

Labels: , ,