Archive for the ‘Hacklab’ Category

Creating a tweet gadget for Google Wave

Saturday, October 10th, 2009

This week bani sent me an invite for trying Google Wave. It’s a great tool and if it remains as open as Google says it will I think it can really change the way we communicate over the internets. I mean, it’s much more flexible than e-mail and it takes collaboration to another level. But, as I said, IMO the “key for success” in this case is to stay open and to support the creation of other servers and implementations(as PyGoWave [which deserves a blog post]).

But enough of cheap talk, I’ll show you the code.

My first “useful” piece of code for Wave is a Tweet Gadget. It’s a simple Google Gadget that takes advantage of the Wave extensions for interacting with the Wave user. What the gadget does is very simple, it takes a tweet id and using the Twitter API it places the tweet inside the Wave. It’s a simple way to quote a tweet.

I must say that the original idea is not mine, it’s rbp‘s idea. We were chatting using Google Wave and he wanted to quote a tweet. That’s how we started looking ways of doing it.

Stateless gadget

I started writing a simple gadget that using the Google Gadgets API makes a request using the Twitter API and shows the tweet in the wave. The problem of this first version was that it does not keep the state, so if you reload/rejoin the wave, you won’t see the tweet, but instead you will see the text box for entering the tweet id.

In this first version you can see how to make a JSON Async Request using the Google Gadgets API. It’s very simple, all you need to do is to set the parameter gadgets.io.RequestParameters.CONTENT_TYPE to gadgets.io.ContentType.JSON and then call gadgets.io.makeRequest(url, callback, params) where callback is a function that receives the JSON object.A very simple example:


function myCallback(obj) {
jsondata = obj.data;
// access the attributes as jsondata['key']
// ...
}
function makesJSONRequest(url) {
params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
gadgets.io.makeRequest(url, myCallback, params);
}

Adding state

Until now the gadget is a simple Google Gadget as it does not use any feature of Google Wave. Also it’s not so useful because it can’t keep the tweet id when you leave the Wave. And worse, people will never see the tweet you quoted. One of the main differences between simple Google Gadgets and Wave Gadgets is their ability to keep, set and change state. By state I mean information. You can keep user preferences, a game score or a tweet id (or even a tweet).

I decided that the easiest way was to store the tweet as it will appear in the wave (with HTML entities and everything). The new version will keep the tweet information when the user enters the tweet id, so everybody in the wave can see the quoted tweet.

You can see the Gadget code to understand how state works in Google Wave, but what’s most important:

  • use a callback (with wave.setStateCallback()) to be aware of state changes
  • wave.getState() returns an state dict-like object which you can set and get information from
  • use wave.getState().get(‘key’) for getting an information
  • and wave.getState().submitDelta({‘key1:’ value1, ‘key2′: value2} for setting information

And that’s it. It’s very simple, hope you enjoy it :)

Transparência HackDay

Friday, October 2nd, 2009

“Two days for hacking the Brazilian politics”

This weekend (October 3rd and 4th) will happen the first “Transparência HackDay” (“Transparency HackDay” in english), a free and open hacking event with focus on bringing together hackers, activists, managers and people with ideas to make government information/public data more accessible for everyone using and writing web tools.

I’m attending and one of my ideas is to hack CET (Companhia de Engenharia de Tráfego / Traffic Engineering Company) data and make them available. The idea is to improve a crawler I wrote (in python ;) ) that downloads and stores data about the traffic in São Paulo every 30 minutes from the “traffic now” CET website (as they don’t store it [or at least don't provide anything]).

More information about the HackDay (in portuguese):
http://www.slideshare.net/esferamobi/transparencia-hackday-proposta

São Paulo Python User Group – May Meeting

Saturday, May 16th, 2009

Every month the GruPy-SP members get together to discuss, chat and/or code.

This month we will meet to watch/present some lightning talks and to talk about our participation at the Fórum Internacional de Software Livre (FISL 10).

The meeting will be hold at the SP HackLab, May 23. More details (in pt-br): GruPy-SP wiki.

See you there :-)

Global Python Sprint Weekend in São Paulo

Thursday, May 8th, 2008

This weekend (May 10th and 11th) will happen the Global Python Sprint Weekend. Like the last PythonBugDay our Python User Group (GruPy-SP) will meet to work together.

This time our meeting will be held at Universidade de São Paulo IME (Instituto de Matemática e Estatística) thanks to RBP and the CCSL (Free Software Competence Centre) =)

Other Python User Groups from Brazil are also meeting to work together, check the wikipage for the PythonBugDay to know if there will be a meeting near you :-) (or you can work from your home sweet home).