Over the weekend, I’ve made a few refinements to my perl script for grabbing my blog index from del.icio.us. It now writes directly to the file on my webserver rather than relying on a redirection of standard output, which consequently means I can check that I’ve got a positive result before replacing the existing file.
To use the script, you’ll need Perl installed including the LWP::UserAgent library, which lets you pass your login details to the del.icio.us server. I found out this was installed by default so didn’t need any extra work. I’ve [highlighted] areas of the script that will need customisation; insert your own details there. I believe the maximum number of results is 100. It is also important to specify a valid user agent string (eg. “Flib/0.5 (+http://www.flib.com)”) – if del.icio.us gets flooded with too many requests from a given agent, it will block its access, which apparently often happens if you leave it with the default agent string.
#!/usr/bin/perl
# Get latest wulfblog posts from del.icio.us
# and write to file.
#
# Wulf Forrester-Barker, 20060313use LWP::UserAgent;
my $posts = [number of posts];
my $username = [del.icio.us username];
my $password = [del.icio.us password];
my $output = [Path to output file];
my $agent = [name/version (+URL)];my $url = “http://del.icio.us/api/posts/recent”;
$url .= “?count=$posts&tag=[tag to filter here (I use “wulfblog”)]“;my $ua = LWP::UserAgent->new;
$ua->agent($agent);
my $req = HTTP::Request->new(GET => $url);
$req->authorization_basic($username,$password);
my $res = $ua->request($req);
if ($res->is_success) {
unless (open RESULTS, “>$output”) {
die “Error opening output file: $!n”;
}
print RESULTS $res->content;
close RESULTS;
} else {
die “Could not get data from del.icio.us servern”;
}
You’re perfectly free to use this script and adapt as required, although I can’t offer any support. I’d be interested to hear if you spot (and fix) a major problem or come up with any useful refinements.
Tags: del.icio.us, web2.0, api, perl, blog index