I found a nice post about doing command line searches of Twitter using Groovy. In a nutshell the code was this:
twitsearch.groovy
#!/usr/bin/env groovy
/*
From http://www.ibm.com/developerworks/java/library/j-groovy09299/
*/
if (args) {
def queryterm = args[0]
def q = "http://search.twitter.com/search.atom?q=${queryterm}"
def feed = new XmlSlurper().parse(q)
feed.entry.each { entry ->
println """\
${entry.author.name} - ${entry.published}
\"${entry.title}\"
${'-' * 72}"""
}
}
else {
println "USAGE: twitsearch.groovy "
}
I tried the same thing in Scala:
twitsearch.scala
#!/bin/sh
exec scala -savecompiled "$0" "$@"
!#
if (args.size > 0) {
import java.net.{URLConnection, URL}
import scala.xml._
val queryterm = args(0)
val q = "http://search.twitter.com/search.atom?q=" + queryterm
val feed = XML.load(new URL(q))
feed \ "entry" foreach { entry =>
println((entry \\ "author" \\ "name" text) + " - " + (entry \\ "published" text))
println("\"" + (entry \\ "title" text) + "\"")
println("-" * 72 )
}
}
else {
println("USAGE: twitsearch.scala ")
}
0 comments:
Post a Comment