#!/usr/bin/perl -w # Creates a Movable Type weblog post containing a day's worth of # del.icio.us links. # v1.0 2004-12-15 # Phil Gyford - phil@gyford.com # http://www.gyford.com/phil/writing/2004/12/16/posting_links_fr.php # Either: # 1) Pass it a YYYY-MM-DD format date on the command line and it will # use the links from that day and set the MT post's "created on" # date to that date. # 2) With no date passed to it, it will use the current date; ideal # for running it daily just before midnight. # By default the title of the MT post will be the number of links. # You can include the tags for each link in the MT post by setting # the flag in the config section. # You'll have to change the two 'lib' paths below, and the details # in the 'Config' section. use strict; use lib "/path/to/your/cgi-bin/lib"; use lib "/path/to/your/cgi-bin/extlib"; # If you have MT Blacklist installed you may need this line to # prevent the script generating errors for some reason; I did. #use lib "/path/to/your/cgi-bin/plugins/Blacklist/lib"; use POSIX; use Net::Delicious; use MT; use MT::Entry; use MT::Blog; ############################################################# # Config - you'll have to edit stuff here... # Movable Type configuration. my $MT_CFG = "/path/to/your/cgi-bin/mt.cfg"; # Get these from the URLs in the MT admin screens. my $BLOG_ID = 8; my $AUTHOR_ID = 1; # del.icio.us account details. my $DEL_USER = 'username'; my $DEL_PASS = 'password'; # The time of day you want the MT post's "created on" time to be. # 24 hour clock, HHMM. my $TIME = '2359'; # Do you want each link's del.icio.us tags included in your MT post? # 1 or 0. my $INCLUDE_TAGS = 1; # End config. ############################################################# # We'll either take a date from the command line or use today. my $date = $ARGV[0] || strftime( "%Y-%m-%d", localtime()); # Check the command line date... if ($date !~ /\d\d\d\d-\d\d-\d\d/) { die "Date format should be YYYY-MM-DD, not '$date'"; } # Initialise Delicious stuff. my $del = Net::Delicious->new({ user => $DEL_USER, pswd => $DEL_PASS }); # Get all the posts for this day from delicious. my @posts = $del->posts({ tag => 'top', dt => $date }); if (scalar @posts == 0) { # There weren't any posts on this day. exit; } # Create the HTML that will be in the blog entry. my $html = ''; foreach my $post (@posts) { $html .= '