Created
June 3, 2021 19:18
-
-
Save mugan86/554cbcbca3794a1b93cd38e38863cc5c to your computer and use it in GitHub Desktop.
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('https'); | |
var xml2js = require('xml2js'); | |
var parser = new xml2js.Parser(); | |
const fs = require('fs'); | |
parser.on('error', function(err) { console.log('Parser error', err); }); | |
var data = ''; | |
https.get('https://www.trafikoa.eus/servicios/IncidenciasTDT/IncidenciasTrafikoTDTGeo', function(res) { | |
if (res.statusCode >= 200 && res.statusCode < 400) { | |
res.on('data', function(data_) { data += data_.toString(); }); | |
res.on('end', function() { | |
console.log('data', data); | |
parser.parseString(data, function(err, result) { | |
console.log('FINISHED', /*err, result*/); | |
console.log(JSON.stringify(result, null, 2)); | |
fs.writeFileSync('euskadi-traffic.json', JSON.stringify(result, null, 2)); | |
}); | |
}); | |
} | |
}); | |
var data_spain = ''; | |
https.get('https://www.dgt.es/incidenciasXY.xml', function(res) { | |
if (res.statusCode >= 200 && res.statusCode < 400) { | |
res.on('data', function(data_) { data_spain += data_.toString(); }); | |
res.on('end', function() { | |
console.log('data', data_spain); | |
parser.parseString(data_spain, function(err, result) { | |
console.log('FINISHED', /*err, result*/); | |
console.log(JSON.stringify(result, null, 2)); | |
fs.writeFileSync('spain-traffic.json', JSON.stringify(result, null, 2)); | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment