Getting scraped parlamento.pt data into google spreadsheet

In this opendata project we’re trying to make it easy for non-techie folks to collaborate and contribute to, and since spreadsheets are still the best way for them to get an idea of what data we already have and do some experiments with them (charts and other visualizations) I decided I should try to connect the couchdb database I created to google spreadsheets.

Like I’ve said in the previous post I’m now using couchdb to store the scraped data. This is because I get for free revisions and also because of the way it exposes data to world using JSON.

For now I’m using couchone and you can see here one of the databases.
I’ve created a view to retrieve the information of one member of parliament that I can call using the following url http://parlamentopt.couchone.com/registointeresses/_design/viewer/_view/by_mpid?key=3

One of the nice things with JSON is that I can slap it into a google spreadsheet almost without any effort.

In fact if the JSON is simple enough (with no hierarchies) using the importData built-in function of the google spreadsheet I get a nice one attribute / one column mapping that works just fine.
But the JSON returned from couchdb is not that straightforward so I had to built a custom function inside of google spreadsheet to do it.

Using Utilities.jsonParse, UrlFetchApp and some methods from the Spreasheet Service I ended up with this code that does what I wanted.

And if I wan’t to I can always export it from Google Spreadsheet to CSV.

Deixe um comentário

O seu endereço de email não será publicado. Campos obrigatórios marcados com *