#!/usr/local/bin/ruby # Get from your personal Google Reader public share. # Post to your WordPress blog. # Written by Dan Woolley on 9/8/07 for http://tzetzefly.com # Command line: ruby postfromgooglereader.rb # where is 'draft', 'live', or 'test' (default is draft) # and is number of days back to get from Google Reader (default is 1) # Stuff you should change blogurl = '' bloguser = '' blogpass = '' # Find this in your Google Reader by choosing 'Shared items' and choosing the 'feed' link googlereader_shareurl = '' # End Stuff to change require 'Time' require 'feed_tools' # gem install feedtools 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 _time = Time.now.utc - (86400 * days_back.to_i) # Change format of title here #title = "items from #{_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 = ['items'] content = '' begin puts "Getting shared Google Reader entries since " + _time.to_s + " for " + post_live + " posting." feed = FeedTools::Feed.open(googlereader_shareurl) feed.entries.each do |x| if x.published > _time content << "
  • \n" content << "

    #{x.title} - #{x.find_node("source/title/text()").to_s}

    \n" content << "

    #{x.summary.gsub('[...]', '...')}

    \n" 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 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 " + _time.to_s end