Created
June 8, 2011 23:15
-
-
Save danwoolley/1015695 to your computer and use it in GitHub Desktop.
Post from Delicious to Wordpress blog
This file contains hidden or 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 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 <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 del.icio.us (default is 1) | |
# Stuff you should change | |
blogurl = '' | |
bloguser = '' | |
blogpass = '' | |
delicious_username = '' | |
# You can leave <tag> 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 << " <li>\n" | |
content << " <a href='#{x.link}'>#{x.title}</a>\n" | |
content << " #{x.description}\n" | |
if x.tags.length > 0 | |
content << " (tags:" | |
x.tags.each do |t| | |
content << " <a href='#{delicious_userurl}/#{t}'>#{t}</a>" | |
end | |
content << ")\n" | |
end | |
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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment