Written by J. Moellenkamp
on March 17, 2013
Reading time: 1 minute
English
del.icio.us
Braindump
About this blog
An horrible hack: Create daily posts of delicious.com links to your blog
As i wanted to revive the daily posts with links i found useful during a day, i hacked a short script into the system to do this task. Maybe it’s useful to someone out there. You have to change at least the red parts of the script:
#!/usr/bin/perl
# Script to publish a daily linkdump into your blog based
# on your delicious account
# v0.2 18.03.2013 jm
# use strict;
#
# It's highly probable that you have to install this modules.
# Easiest way: perl -MCPAN -e 'install Net::Delicious'
#
use Net::Delicious;
use WordPress::XMLRPC;
use WWW::Shorten::Bitly;
use Date::Format;
use Log::Dispatch::Screen;
#
# Adapt this $config_ variables to your needs.
#
<font color="red">
# Filename for saving Timestamp of the last run
my $config_timestampfile="";
# Username at delicious
my $config_delicious_username="";
# Password at delicious
my $config_delicious_password="";
# Username at bitly.com
my $config_bitly_username="";
# API key for bitly
my $config_bitly_apikey="";
# username to post into your blog
my $config_blog_username="";
# password to post into your blog
my $config_blog_password="";
# XMLRPC Endpoint for your blog software
my $config_blog_xmlrpcproxy="";
# Category for the blog entry.
# The name of it, not the number ... at least for S9Y
my $config_blog_category="";
# 0 = draft, 1 = publish
my $config_blog_publish=0;
</font>
# some initialisation
my $numberoflinks=0;
my $blogentry;
#
# Doing the timestamp stuff in order to ensure
# that just links entered since the last script run
# will be put into the blog entry
#
my @zt = gmtime(time); # Delicious wants Zulu-Time.
my @lt = localtime(time); # Joerg wants localtime
my $datestring = strftime("%d-%b-%Y", @lt);
my $delicioustime_new = strftime("%Y-%m-%dT%H:%M:%SZ", @zt);
open(TIMESTAMP,"$config_timestampfile");
my $oldtime = <TIMESTAMP>;
chomp($oldtime);
close(TIMESTAMP);
open(TIMESTAMP,">$config_timestampfile");
print TIMESTAMP "$delicioustime_new";
close(TIMESTAMP);
# Connecting to Delicious and create the text of the blog entry.
# While doing so, get short-links from bit.ly
my $del = Net::Delicious->new({user => "$config_delicious_username",
pswd => "$config_delicious_password"});
$blogentry .= "<ul>\n";
foreach my $p ($del->posts({dt=>"$oldtime"})) {
my $url=$p->url();
my $description=$p->description();
my $extended=$p->extended();
my $tags=$p->tags();
my $shorturl = makeashorterlink($url, "$config_bitly_username", "$config_bitly_apikey");
$blogentry .= "<li>\n";
$blogentry .= "<a href=\"$shorturl\">$description</a><br>\n";
$blogentry .= "$extended<br>\n" if $extended ne "";
my @tag=split(" ",$tags);
my $linkified_tags="";
foreach my $unlinkified_tag (@tag) {
$linkified_tags = $linkified_tags .
"<a href=\"https://delicious.com/" .
$config_delicious_username . "/" . $unlinkified_tag .
"\">" . $unlinkified_tag . "</a> ";
}
$blogentry .="<small> (tags: $linkified_tags)</small><br>\n"
if $linkified_tags ne "";
$blogentry .= "</li>\n";
$numberoflinks++;
}
$blogentry .= "</ul>";
# No links? The story ends here!
exit(0) if $numberoflinks==0;
# Send blog entry.
my $o= WordPress::XMLRPC->new({
username => "$config_blog_username",
password => "$config_blog_password",
proxy => "$config_blog_xmlrpcproxy",
});
my @entrystructure = {
categories => [
"$config_blog_category"
],
title => '<font color=red>::linkbuf for </font>' . $datestring,
description => "$blogentry"
};
$o->publish($config_blog_publish);
$o->newPost(@entrystructure) or die($o->errstr);