Sunday, October 16, 2005

Let watir do the job

AutoLinking is a very convenience feature for almost every blog writer. For example, when you are writing about antlr, you may want to give a link to, and a smart blog authoring tool should be able to do that for you. But as Wesner Moise mentioned on his blog , currently no blog-posting tool provides that service.

So I wrote a watir script(Watir is a great web application testing framework in Ruby) to help me. First it uses regular expression to do autolinking, then go to the website and publish the post (so I do not have to click all the links and wait for a reply).

Here is the code:

require 'watir'
include Watir

#Start your writing here
title = "Let watir do the job"
content = <<EOF
I love watir !

#Polish and Autolinking etc
content = content.gsub(/\n/, ' ') #replace linebreak with whitespace
content = content.gsub(/\bwatir\b/, '<a href="">watir</a>')

#Go to the website
ie =

ie.text_field(:name, "username").set("yourusrename")
ie.text_field(:name, "password").set("yourpassword"), "Sign in").click

#Open blog, "your blog title").click

#Create new post, "Create new post").click

#Publish it ("value=" is faster then "set")
ie.text_field(:name, "title").value=(title)
ie.text_field(:name, "postBody").value=(content)
ie.button(:value, "Publish Post").click


Post a Comment

<< Home