Skip to content

Instantly share code, notes, and snippets.

@tommorris
Created December 9, 2008 07:42
Show Gist options
  • Save tommorris/33831 to your computer and use it in GitHub Desktop.
Save tommorris/33831 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'xmlrpc/client'
# USERNAME
username = ""
# PASSWORD
password = ""
# DOMAIN - of the style tommorris.org
domain = ""
# XMLRPC PATH
xmlrpcpath = "/"
# EDITOR - vim, gvim, emacs or gedit for the fail
editor = "vim"
# create file and open up vim
filename = "/home/tom/tmp/blog" + Time.now.hash.abs.to_s + ".html"
system(editor + " " + filename)
# read file in
exit unless File.exists?(filename)
file = File.open(filename)
# pull out title
poss_title = file.readline
if poss_title =~ /^Title: .*$/
title = poss_title.gsub(/^Title: (.*)\n$/, "\\1")
end
file.close
file.reopen(filename)
if title.nil?
description = file.readlines.join("")
else
description = file.readlines.slice(2..-1).join("")
end
description.gsub!(/(.*)\n$/m, "\\1") if description =~ /\n$/m
# push to server
server = XMLRPC::Client.new(domain, xmlrpcpath)
post = {:description => description}
post[:title] = title unless title.nil?
response = server.call("metaWeblog.newPost", 1, username, password, post, true) unless description.nil? || description.length == 0
if response == "0"
print "Failed -- " + filename + "\n"
else
print "Success!\n"
File.delete(filename)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment