Untitled

Submitted by reeses on Thu, 2002-10-31 07:53.

I wanted the ability to compose log entries offline, and then have a tool post them when my computer is back online. I thought about doing something clever with my email, and writing a mail->blog filter (which I will probably end up doing anyway) that sits in procmail and looks for a formatted message. As it was, I stumbled upon this post when searching for "ruby blogger".

So, I wrote the following script to take all unposted files *.np from c:\posts (hey, my laptop runs win2k), suck them into a string, spit it over xmlrpc to the blogger server, and then touch a file *.xx to indicate that it has been submitted. The reason I did the stamp instead of renaming the file is that File#rename seemed to behave strangely on this machine, and I'm too tired to suss it out.

The script is below. You'll need to change the blogId, username, and password, unless you happen to have those equal to the bogus values.

#!/usr/local/bin/ruby

require "xmlrpc/client"

server = XMLRPC::Client.new( "plant.blogger.com", "/api/RPC2" )
blogger = server.proxy( "blogger" )
appKey = "EFC73821AFC4CBEE72B07D4F12D5469C445AD923EF00"
blogId =
username =
password =

Dir["C:/posts/*.np"].sort! { | a, b | File.new(a).mtime <=> File.new(b).mtime }.each {
| f |
stamp = f.sub(/.np$/, ".xx")
unless FileTest.exist?(stamp) then
contents = IO.readlines(f)
post = contents.join
puts "Posting article
" + post + "-----------"
blogger.newPost( appKey, blogId, username, password, post, true )
`touch #{stamp}`
end
}

Post new comment

Captcha Image: you will need to recognize the text in it.
Please type in the letters/numbers that are shown in the image above.