Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Add Comment
Please, Sign In to add comment