Created
July 6, 2015 14:55
-
-
Save Nullpo/29896c950b70820582f8 to your computer and use it in GitHub Desktop.
Vot.Ar - CABA 2015 -> bajar votos publicos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Scriptcito para bajarse los datos publicos que se hallan en https://www.2015elecciones.gob.ar/ | |
| var request = require("request"); | |
| var assert = require('assert'); | |
| var MongoClient = require('mongodb').MongoClient; | |
| var mesas = 9044; | |
| var Utils = { | |
| urlForMesa: function urlForMesa(mesa) { | |
| return "https://apielecciones.buenosaires.gob.ar/api/mesa?id=" + mesa; | |
| }, | |
| parseResponse: function createParseResponse(mesa, db){ | |
| return function parseResponse(error, response, body){ | |
| if(error){ | |
| console.log("Error al leer la mesa " + mesa); | |
| } else { | |
| var collection = db.collection('documents'); | |
| collection.insert({ | |
| mesa: mesa, | |
| body: body | |
| }, function(err, result){ | |
| if(err){ | |
| console.log("Error al escribir la mesa " + mesa); | |
| } else { | |
| console.log("Mesa " + mesa + " guardado correctamente"); | |
| } | |
| }) | |
| } | |
| }; | |
| } | |
| }; | |
| MongoClient.connect("mongodb://localhost:27017/votar", function(err, db) { | |
| assert.equal(null, err); | |
| console.log("Connected correctly to server"); | |
| for(var mesa = 1; mesa <= mesas ; mesa++){ | |
| request({ | |
| url: Utils.urlForMesa(mesa), | |
| json:true | |
| }, Utils.parseResponse(mesa, db)); | |
| } | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment