January 24, 2002

Someone found my instablog

Someone found my instablog utility helpful. That's cool. Maybe I'll write up a short webpage on how to do it. Or heck, I'll just write it here.

I use tcsh - I made an alias named "blog" like this:

alias blog 'vim /home/siffert/blogs/`date +%y%m%d%H%M.blg`'

Then, in my .vimrc, I put these commands:

autocmd! BufWritePre,FileWritePre	*.blg	set bin
autocmd  BufWritePre,FileWritePre	*.blg 	'[,']!instablog
autocmd  BufWritePost,FileWritePost	*.blg	set nobin

Finally, I wrote a short perl utility called instablog. Here is the code.

#!/usr/bin/perl

use Carp;
use Blogger;

my $b = Blogger->new(appkey=>"59E3D4AB5F4CD29FDF043D3E38DA5CC5CD2716C603");

$b->BlogId(YOUR_ID_HERE);
$b->Username(YOUR_USERNAME_HERE);
$b->Password(YOUR_PASSWORD_HERE);

my $txt = "";
my $id = "";
while () {
    if (/^##Id: (.*?)$/) { $id = $1; }
    else { $txt .= $_; }
}

if ($id == "") {
    $id = $b->newPost(postbody=>\$txt,publish=>1) || croak $b->LastError();
}
else 
{
    $b->editPost(postbody=>\$txt,postid=>$id,publish=>1) || croak $b->LastError();
}

print "##Id: $id\n$txt";

It requires Aaron's Blogger.pm package.

The end result? I type "blog", an editing window comes up, I type and type, I hit :wq, and it posts to my blog. If I vi the file afterward and make changes, it will change the entry on my web page the same way. Neat! Posted by Curt at January 24, 2002 12:25 AM