Tuesday, August 11, 2009

Groovy Web Console

Here is a neat little site that provides a web based Groovy console with the ability to run Groovy scripts. It is deployed on the Google App Engine (very cool idea).

Just for fun, here is a little groovy script to read a CNN feed. This is also running as a bot within our environment:

def url = "http://rss.cnn.com/rss/cnn_topstories.rss"
println 'The top three news items today:'
def items = new XmlParser().parse(url).channel[0].item
for (item in items[0..2]) {
println "${item.title.text()} - ${item.link.text()}"
println item.description.text()
println '----'

Instant Bots - Now with Groovy

Over the years, Instant has developed Sametime bots in Java, .Net, and VB. We have also created OCS bots in VB and .Net. These have all been fun projects.

However, nothing matches the pleasure of developing IM applications using groovy.

Groovy is light weight and just plain fun. I'm especially impressed with XMLSlurper - which makes dealing with XML painless (well, actually productive).

Here is a little weather bot developed in groovy.

1: Let's login to Sametime

public weatherBot() {
registerAndLogin("ST", "stserver.instant-tech.com", "weather bot", "");

2: Let's say Hello when we receive an IM:

public void ImReceived(ITFIMEvent ImEvent)
String msgType = ImEvent.getMsgServiceType()
String prefix = "Welcome to the Instant Weather bot. Please enter a zipcode:"
MsgServiceInterface myService = getMsgService(msgType)

prefix ,

3: Let's return the weather (with a little help from XMLSlurper)

public void ImTextReceived(ITFIMEvent ImEvent)
String msgType = ImEvent.getMsgServiceType()
MsgServiceInterface myService = getMsgService(msgType)

def baseUrl = "http://weather.yahooapis.com/forecastrss"
String zip = ""
String outPut = ""

//def zip = '03824'
zip = ImEvent.getText()
def url = baseUrl + "?p=" + zip
def xml = url.toURL().text

def rss = new XmlSlurper().parseText(xml)
outPut = "Your temp is " + rss.channel.item.condition.@temp + " and conditions are: " + rss.channel.item.condition.@text


Interesting Flex on Grails Book

Here is a link to a very interesting Flex on Grails book.

In researching our next platform, I'm impressed with Grails. Grails seems to create a platform where applications are developed with few lines of code, they use very efficient components (i.e. groovy), and the focus is on a high quality applicaiton built on industry best practices.

As we extend our UI from Notes, we will take advantage of both Grails and Groovy.