Adding twitter to my blog using Scala

Having added javascript widgets to my blog a few months ago, I found that this slowed the page downloads a lot. Here is a way to speed this up again, by pre-processing the work with a Scala script, and using iFrames to include the result.

Here are the short steps to do this:

  1. I wrote a Scala Program (see source) to take the twitter Atom feed, and generate xhtml from it.
  2. I wrote a shell script to run the compiled scala jar
    #!/bin/bash
    
    export CP=$HOME/java/scala/lib/scala-library.jar:$HOME/java/scala/lib/learning.jar
    
    /usr/bin/java -cp $CP learning.BlogIFrame $\*
    
  3. Then I just started a cron job on my unix server to process the script every half an hour
    $ crontab -l
    5,36 \* \* \* \* $HOME/bin/twitter.sh $HOME/htdocs/tmp/blogs.sun.com/tweets.html
    
  4. Finally I added the iFrame to my blog here pointing to the produced html <IFRAME src="http://bblfish.net/tmp/blogs.sun.com/tweets.html" height="300" frameborder="0"></IFRAME>

As a result there is a lot less load on the twitter server - it only has to serve one atom feed every half an hour instead of 1000 or so a day - and my html blog page does not stall if the twitter site itself is overloaded.

Also I learnt a lot about Scala by doing this little exercise.

Comments:

Interesting, I 've just bought a book on scala.
What's your feed back on scala, what did you learn ?

Posted by Christian Fauré on April 29, 2009 at 08:15 AM CEST #

Scala is cool, didi you know that dannyayers.com is some scala aggregating twine?

it's here: http://scm.trialox.org/sandbox/org.trialox.sandbox.twine/

cheers,
reto

Posted by Reto Bachmann-Gmür on April 29, 2009 at 08:48 AM CEST #

Christian, I am still exploring Scala, and have not yet come to a final judgement yet. I like the way one can say a lot in little space, yet still retain the clarity of strong typing. Being able to write XML directly in the lanuage is neat. For the moment it still takes me more time to write a Scala Program than the equivalent Java one, as I am more familiar with Java. Of course I really appreciate how close Scala is to Java, for that very same reason. The pattern matching part of Scala is very helpful, though I did not use that this much here. I think there is still a lot for me to discover here...

Reto: I don't quite understand what you wrote. Are you saying dannyayers.com is a site running Scala? And how does that fit with twine? That sounds very interesting...

Posted by Henry Story on April 29, 2009 at 09:00 AM CEST #

yes what you see on dannyayers.com is the result of a scala script running on the trialox platform aggregating the RDF representation of ttp://www.twine.com/twine/1247b40gj-21j

Posted by Reto Bachmann-Gmür on April 29, 2009 at 09:27 AM CEST #

scala> "blah&blah&blah&".replace("&", "&amp;")
res2: java.lang.String = blah&amp;blah&amp;blah&amp;

Posted by James Iry on April 29, 2009 at 12:37 PM CEST #

Thanks for the hint James Iry, I checked the new version in with the simpler code:

http://is.gd/vpXP

Posted by Henry Story on April 29, 2009 at 01:37 PM CEST #

Post a Comment:
Comments are closed for this entry.
About

bblfish

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today