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 www.antlr.org, 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 !
EOF

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

#Go to the website
ie = IE.new
ie.goto("http://www.blogger.com/start")

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

#Open blog
ie.link(:text, "your blog title").click

#Create new post
ie.link(:text, "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

0 Comments:

Post a Comment

<< Home