#!/usr/bin/perl # # Post Delicious Links to MovableType with XPath # (MT installed on local machine) # ##### ## ## Minor tweaks made by Noah Brier ## Site: NoahBrier.com ## Date: 07.14.05 ## Use with: Tags plugin (http://www.sixapart.com/pronet/docs/powertools) ## Serious thanks to the people who created this, you guys rock. ## ##### ## Author: ## Matthew Trentacoste ## site at squarewithin dot com ## 27 January 2004 ##### # # Original source: # Jeffrey Veen # jeff at veen dot com # 10 December 2003 # # Distributed under the Creative Commons "Share Alike" license. # http://creativecommons.org/licenses/sa/1.0/ # ### # load modules use POSIX; #### use lib "path/to/mt/lib"; # change to your installation #### use MT; use MT::Entry; use MT::Category; use MT::Placement; use XML::XPath; # set up local variables - change to suit your needs # author number my $MTauthor = "AUTHOR ID"; # linklog blog number my $MTblogID = "BLOG ID"; # path to MT config file my $MTconfig = "/path/to/mt/mt.cfg"; # del.icio.us login my $delUser = "USERNAME"; my $delPW = "PASSWORD"; # End config ############################################################## # get today's date and format it my $date=strftime( "%Y-%m-%d", localtime()); # go get the xml file my $xml = `curl -s -u $delUser:$delPW http://del.icio.us/api/posts/recent`; # get a new XPath object my $xp = XML::XPath->new(xml => $xml); # create instance of MT my $mt = MT->new( Config=>$MTconfig ) or die MT->errstr; # see if anything was posted to day my $any_found = 0; # grab XML values and write HTML foreach my $posts ($xp->find('//post')->get_nodelist) { # check if title already exists ##### # eventually want to filter by date, but this is sufficient for now ##### my $entered = 0; my @check_entry = MT::Entry->load ({ blog_id => $MTblogID }); for ( $i=0; $i < scalar @check_entry; $i++ ) { # some stupid stuff to force them to strings for comparison my $temp1 = "".@check_entry[$i]->title; my $temp2 = "".$posts->find('@description'); if ( $temp1 eq $temp2 ) { $entered = 1; } } # if not already found, add to the database if ( $entered == 0 ) { # create a new entry my $entry = MT::Entry->new; $any_found = 1; print ( $posts->find('@description') . "\n" ); # add all the information, including writing the time from del.icio.us $entry->blog_id($MTblogID); $entry->status(MT::Entry::RELEASE()); $entry->author_id($MTauthor); $entry->title($posts->find('@description')); $entry->text($posts->find('@extended')); $entry->text_more($posts->find('@href')); $entry->excerpt($posts->find('@extended').'

Tags: '.$posts->find('@tag')); $entry->keywords($posts->find('@tag').' '); $entry->convert_breaks(0); $entry->allow_comments(1); my $test = "".$posts->find('@time'); my @create_time = split(/-|T|:|Z/,$test); $entry->created_on(@create_time[0] . @create_time[1] . @create_time[2] . @create_time[3] . @create_time[4] . @create_time[5]); # save entry $entry->save or die $entry->errstr; } } # update if any new found if ( any_found == 1 ) { # rebuild the site $mt->rebuild(BlogID => $MTblogID ) or die "Rebuild error: " . $mt->errstr; # ping aggregators $mt->ping($MTblogID); }