Last active
November 24, 2020 15:27
-
-
Save hhkaos/7965e82df89826a0eb8d06a04b75ee8f to your computer and use it in GitHub Desktop.
Script en node para descargar datos de escolarización de la Junta de Andalucía
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
var https = require('follow-redirects').https; | |
var fs = require('fs'); | |
let data = { | |
idProvincia: '04', | |
idMunicipio: '04013', | |
idTipoVia: '', | |
tipoVia: 'AVENIDA', | |
codIberVia: 'AVENIDA,FEDERICO GARCIA LORCA', | |
nombreVia: 'FEDERICO GARCIA LORCA', | |
numeroVia: '36', | |
radioBusqueda: '', | |
tipoZona: 'N_INFCICSEG', | |
posicionX: '', | |
posicionY: '' | |
} | |
postData = Object.keys(data).map(function (k) { | |
return encodeURIComponent(k) + '=' + encodeURIComponent(data[k]) | |
}).join('&'); | |
var options = { | |
'method': 'POST', | |
'hostname': 'www.juntadeandalucia.es', | |
'path': '/educacion/educasig/escolarizacion/servlets/ConsultaPuntuacionServlet', | |
'headers': { | |
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' | |
} | |
}; | |
fs = require('fs'); | |
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0 | |
var req = https.request(options, function (res) { | |
var chunks = []; | |
res.on("data", function (chunk) { | |
chunks.push(chunk); | |
}); | |
res.on("end", function (chunk) { | |
var body = Buffer.concat(chunks); | |
body = body.toString(); | |
body = JSON.parse(body) | |
//Colegios limitrofes | |
colegios = body.listaCentrosEnAreasLimitrofes; | |
new_colegios = colegios.map(function (elem, i) { | |
var obj = elem; | |
obj = { | |
"type": "Feature", | |
"geometry": { | |
"type": "Point", | |
"coordinates": [parseFloat(elem.longitud.replace(",", ".")), parseFloat(elem.latitud.replace(",", "."))] | |
} | |
} | |
obj.properties = elem | |
return obj; | |
}) | |
let fc = { | |
"type": "FeatureCollection", | |
"features": new_colegios | |
} | |
const output = JSON.stringify(fc, null, 2); | |
console.log(output); | |
fs.writeFile('output.geojson', output, function (err) { | |
if (err) return console.log(err); | |
console.log('Salida en output.geojson'); | |
}); | |
}); | |
res.on("error", function (error) { | |
console.error(error); | |
}); | |
}); | |
req.write(postData); | |
req.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment