?

Log in

No account? Create an account
Daily links (del.icio.us to LiveJournal) Perl script - Z303 [entries|archive|friends|userinfo]
Zoe

[ website | Z303 ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Daily links (del.icio.us to LiveJournal) Perl script [Feb. 16th, 2005|11:34 pm]
Zoe
Update 2005-03-08 I've done some more work on the script and released a new version (0.2).

Ok, if anyone is interested inside the cut is my current version of the daily links script, as I said, based on Jeffrey Veen original del.icio.us to Moveable Type version (the link also contains the XSLT stylesheet you will need to run this).

Everything is still very bare bones, but it does work and is at least semi-usable.


#!/usr/bin/perl
#
# Post del.icio.us Links to LiveJournal
#
#
# Distributed under the Creative Commons "Share Alike" license.
# http://creativecommons.org/licenses/sa/1.0/
#

use strict; # Silly not to be

use POSIX qw(strftime); # Date calculation

use LJ::Simple; # Livejournal API

use XML::XSLT; # http://xmlxslt.sourceforge.net/

# set up local variables - change to suit your needs.

my $LJUser = "test";
my $LJPW = "test";

my $delUser = "test";
my $delPW = "test";

my $xsl ="links.xsl";

# get today's date and format it

my $date = strftime( "%Y-%m-%d", localtime());

my $subjectline ="Links for " . $date;

# go get the links
my $xml = `curl -s -u $delUser:$delPW http://del.icio.us/api/posts/get?dt=$date`;

# set up xslt stuff and transform the xml to html
my $xslt = XML::XSLT->new ($xsl);
$xslt->transform ($xml);

my $guts=$xslt->toString;

# post to LJ
my $lj = new LJ::Simple ({
user => $LJUser,
pass => $LJPW,
});

(defined $lj)
|| die "$0: Failed to log into LiveJournal: $LJ::Simple::error\n";


my %Event=();

$lj->NewEntry(\%Event) ||
die "$0: Failed to create new entry: $LJ::Simple::error\n";


$lj->SetSubject(\%Event,$subjectline)
|| die "$0: Failed to set subject - $LJ::Simple::error\n";

$lj->Setprop_preformatted(\%Event,1) ||
die "$0: Failed to set property - $LJ::Simple::error\n";

$lj->SetEntry(\%Event,$guts)
|| die "$0: Failed to set entry: $LJ::Simple::error\n";

my ($item_id,$anum,$html_id)=$lj->PostEntry(\%Event);
(defined $item_id)
|| die "$0: Failed to post journal entry: $LJ::Simple::error\n";


LinkReply