Twitter Client in Scala
I’ve been playing with Scala a bit lately. Tonight, I was fooling around with Scala using an online, interactive shell called lotrepls. I decided to write a script that would call the Twitter API and return me the status for a Twitter user. The script takes a Twitter user name as input and prints that user’s status to the screen. It turns out that Scala has some built-in XML parsing capabilities that makes this really easy.
This is the script.
import java.net._
import scala.xml._
val screenName = "robbr" // Follow me!
val url =
new URL("http://twitter.com/users/show.xml?screen_name=" +
screenName)
val conn = url.openConnection
val xml = XML.load(conn.getInputStream)
val status = (xml\"status"\"text").text
println(screenName + ": " + status)
I’ll quickly break down the script line by line for non-Scala people. Not that I’m a Scala export myself.
- Scala is completely interoperable with Java. Scala can call Java and Java can call Scala. In the first line, I am importing all classes in the java.net package to use for making a HTTP request later in the script.
- In the second line I am importing all classes in the Scala XML package.
- I set the screen name which is input to the Twitter status API call. I could instead prompt the user for the screen name using Console.readline(), but this doesn’t work with lotrepls.
- Set the URL for the Twitter status API.
- Open a URL connection.
- Load the XML output of the HTTP request into a variable. The “val” modifier makes the variable final, therefore it can’t be changed.
- I use an XPath like statement to navigate the XML for the data element I am looking for. I get only the text of that element.
- Output the screen name and status to the screen.
This script can simply be cut and pasted into lotrepls. Remember to switch to Scala before running the script. Use CTRL+ENTER to execute. That’s all there is to it. Enjoy.
Larry Ellison’s Cloud Computing Comments Revisited
Back on September 26, 2008, Larry Ellison (CEO Oracle) made the following comments about cloud computing. Larry was quoted by the Wall Street Journal as saying…
“The interesting thing about cloud computing is that we’ve redefined cloud computing to include everything that we already do. I can’t think of anything that isn’t cloud computing with all of these announcements. The computer industry is the only industry that is more fashion-driven than women’s fashion. Maybe I’m an idiot, but I have no idea what anyone is talking about. What is it? It’s complete gibberish. It’s insane. When is this idiocy going to stop?
“We’ll make cloud computing announcements. I’m not going to fight this thing. But I don’t understand what we would do differently in the light of cloud computing other than change the wording of some of our ads. That’s my view.”
With the announcement yesterday that Oracle is buying Sun, it will be interesting to see what this means for Sun’s cloud computing technology.
The rant against cloud computing was well covered at the time, but I couldn’t help but to think about it again in light of yesterday’s big news. Actually, my favorite part of the quote is that part about software being like woman’s fashion. So true sometimes.
End of An Era
Sun agrees to be acquired by Oracle. This is huge news in so many ways. Oracle will own MySQL, the most widely used open source, relational database. They will now own OpenOffice/StarOffice, a competitor to Microsoft Office. Oracle acquired BEA last year, so acquiring Sun makes that acquisition all the more interesting. And Sun owns some up the best cloud computing technology out there. Hmmm, I can only begin to think about what this does to the software landscape.
Toodle-Li-Do, Toodle-Li-Dum
I have finally found a satisfying to-do list solution for my iPod Touch. Its called ToodleDo. For $3.99 ToodleDo has an iPhone/Touch application that can sync up to a ToodleDo basic (free!) Web account. I’ve been looking for this since I got my Touch over a year ago.
Java Support Added To Google App engine
In what is great news for the Java community, Google has added support for Java to the Google App Engine.