Created
June 8, 2011 23:20
-
-
Save danwoolley/1015704 to your computer and use it in GitHub Desktop.
Post from Google Reader to Wordpress blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 <post_type> <days_back> | |
# where <post_type> is 'draft', 'live', or 'test' (default is draft) | |
# and <days_back> 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 << " <li>\n" | |
content << " <p><a href='#{x.link}'>#{x.title}</a> - #{x.find_node("source/title/text()").to_s}</p>\n" | |
content << " <p>#{x.summary.gsub('[...]', '...')}</p>\n" | |
content << " </li>\n" | |
end | |
end | |
rescue => e | |
puts "Error: " + e.to_s | |
end | |
puts title | |
if content.length > 0 | |
content = "<ul>\n" + content | |
content << "<ul>\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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment