Urllogpg.pl, an irssi script for logging URLs to postgresql database

2012-05-27

I like logging stuff. Usually I don't do much of anything with the data I log, but every once in a while I might accidentally find some use for some of the data.

Recently I've migrated away from MySQL, into PostgreSQL. For logging links to a MySQL database there was Riku Voipio's srcipt, mysqlurllogger.pl, but I couldn't find a ready-made script for logging them to PostgreSQL database so I rolled one myself.

The script isn't very feature-rich, but it gets the job done. It has one twist, though, it fetches the title of the linked page. The feature comes with a cost, as it needs the LWP perl module to be installed. Another requirement for the script is naturally the PostgreSQL database driver, DBI. Also, see the edit below.

The script expects a table called “links” defined more or less like this:

id: integer primary key, with a sequence for auto-increment
channel: text
time: timestamp
nick: text
link: text
title: text

Once you've created the database and meet the requirements, drop the script to you script folder (most likely ~/.irssi/scripts/), insert your database name, username and password in and load the script in irssi with /load urllogpg.pl.

The script can be found here. It is released under simplified BSD-licence, so… As RMS would put it, happy hacking!

Edit

Actually now, after a bit more testing, it seems automatically fetching the page titles may not a good idea. Irssi handles scripts in the same thread as the core logic, so while waiting for the scripts to be run irssi otherwise stops any other activity. For title fetching this means that if the connection to host of the web page times out (or the page is huge/the connection is poor) the script takes an awful lot of time to return. During this time irssi is unsable and the connection to the irc server may even time out.

I've now disabled the feature by default, but it's very easy to enable in the script.

tl;dr: think if you really want to enable the title fetching.

Edit 2

The script is moved to github.