#!/usr/local/bin/ruby # Get from your personal del.icio.us share. # Post to your WordPress blog. # Written by Dan Woolley on 9/8/07 for http://tzetzefly.com # Command line: ruby postfromdelicious.rb # where is 'draft', 'live', or 'test' (default is draft) # and is number of days back to get from del.icio.us (default is 1) # Stuff you should change blogurl = '' bloguser = '' blogpass = '' delicious_username = '' # You can leave off to include all your tags, or use it to restrict your focus. # I recommend you use something like "post:blogname" for the tag, so that only specific # items you tag with that end up posted on your blog. delicious_tag = '' # End Stuff to change delicious_rssurl = 'http://del.icio.us/rss/' + delicious_username + '/' + delicious_tag delicious_userurl = 'http://del.icio.us/' + delicious_username require 'Time' require 'feed_tools' require "xmlrpc/client" # Second argument passed is 'live' or 'draft' or 'test'. # where 'live' posts immediately on your blog, 'draft' will sit in your draft posts, # and 'test' just displays the output on the console. # Default is 'draft'. post_live = ARGV[0] post_live = 'draft' if post_live == nil # First argument passed is the days back to pull. # Default is 1. days_back = ARGV[1] days_back = 1 if days_back == nil links_time = Time.now.utc - (86400 * days_back.to_i) # Change format of title here #title = "items from #{links_time.strftime('%m.%d.%Y')}" title = "items for #{Time.now.strftime('%m.%d.%Y')}" # Change categories/tags for post here # This must be an array of strings categories = ['links'] content = '' begin puts "Getting shared del.icio.us items since " + links_time.to_s + " for " + post_live + " posting." feed = FeedTools::Feed.open(delicious_rssurl) feed.entries.each do |x| if x.published > links_time content << "
  • \n" content << " #{x.title}\n" content << " #{x.description}\n" if x.tags.length > 0 content << " (tags:" x.tags.each do |t| content << " #{t}" end content << ")\n" end content << "
  • \n" end end rescue => e puts "Error: " + e.to_s end puts title if content.length > 0 content = "
      \n" + content content << "
        \n" puts content if post_live != 'test' puts "Posting entry to " + blogurl begin # Post Links To Blog Via XMLRPC server = XMLRPC::Client.new(blogurl, "/xmlrpc.php") newPost = Hash.new newPost['title'] = title newPost['description'] = content newPost['categories'] = categories result = server.call("metaWeblog.newPost", 1, bloguser, blogpass, newPost, post_live == 'live') rescue XMLRPC::FaultException => e puts "XMLRPC Error: " puts e.faultCode puts e.faultString rescue StandardError => e puts "Error: " + e.to_s end end else puts "No new items since " + links_time.to_s end