RSS 2.0 New Entries Syndication Feed Atom 0.3 New Entries Syndication Feed

Show blog menu v



Use it



Sibling projects

RIFE powered

Valid XHTML 1.0 Transitional

Valid CSS!

Blogs : Archives

< JIA: Deploying Apache Axis in Mission-Critical Environments by Eugene Ciurana 
Groovy, Bla-bla List and You
I had a large list of todo items in my inbox this morning and I had to get them into Bla-bla List ( I use Bla-bla to track my todo items throughout the day and so sometimes I need to mass-add items to a list. "But how!" you ask? "Bla-bla has no import feature" you say? Au contraire mon frère! Bla-bla has a complete REST API and so it's easy to write a script to mass-add whatever you want.

And so begins my writing of another shell script to automate a tedious process...

But wait! This wouldn't be entertaining if we just did this in shell or Perl... This is a chance to learn something... Hmmm... What to learn? I know! Groovy! I've wanted to play with Groovy for a long time. This is perfect!

So I fire up an instance of VIM (more on why I did this later) and start plugging away following the tutorials. I end up producing a script that looked HORRIBLE, but actually did a pretty decent job. So I make a pass through it again. Once you've done something once, the second time around you'll do better. I finally got it to a place I was happy with.

Rudimentary error checking, creation of a new list, semi-reusable components incase I want to expand later... Yes... This will do nicely.

Groovy has really impressed me and has already begun to supplant my main-stay of scripting, Perl. I'm really quite looking forward to playing with it more. From what I've seen and done it does take some discipline to stay in line and not create total anarchy in your code. The first iteration of the script was quite nasty and used a shell command to do the URL heavy lifting. Then of course I remembered I was in Java and I fixed my error. :)

The reason I started out using VIM for editing was that I had forgotten that Groovy had an Eclipse plugin. I use Eclipse in my day-to-day Java work and despite all it's faults (VERY VERY slow on Linux... I thought SWT was supposed to cure that) I still love it to death. The Eclipse plugin was simple, but it did give very nice error messages back on the state of my code and I was thankful for that. I still haven't played with the plugin quite enough so don't ignore it completely because it's simple. Even in it's current state the error messages are VERY useful.

I've placed the script in Bla-bla List's document space for your perusal. It's pretty simple. Make sure you have a Bla-bla List account and edit the script to fill in the login and password. Once you've done that run it like this:

$ groovy maketodolist.groovy "My List Name" /home/jboyens/todolist.txt

Each line in the file will be a new item on the list, so if you need to do a bit of cleaning up do it prior to running. The script will give some nice output on what it is doing and whether it's succeeding or not. Now, this may not work for some more exotic files because I only do simple URL encoding, so if you mess something up it isn't my fault. :)

I hope it's of use to you. I know I'll be using it at least once in a while.
posted by JR Boyens on Nov 1, 2005 5:06 PM : 1 comment [permalink]


Re: Groovy, Bla-bla List and You
Nice script:)

It would be even Groovier if you used GStrings:

def command = "/addentry" +
"?submission=credentials" +
"&login=$login" +
"&password=$password" +
"&submission=add" +
"&listId=$listId" +
'&name=${URLEncoder.encode(name, "UTF-8")}'

Add a new comment

Comments on this blog entry have been closed.

< JIA: Deploying Apache Axis in Mission-Critical Environments by Eugene Ciurana 
Google web