Last active
November 30, 2017 21:48
-
-
Save nicholasess/ffabb67f885c04622846 to your computer and use it in GitHub Desktop.
Recuperando dados do aquivo .bd e transformando em json
This file contains 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
*** | |
Empresa: TAM Numero do voo: 3001 DI: 0 Tipo: N Origem: SBEG Destino: SBKP | |
Saida prevista: 10/02/14 10:10:10 | |
Saida real: 10/02/14 10:10:10 | |
Chegada prevista: 10/02/14 13:11:00 | |
Chegada real: 10/02/14 13:11:00 | |
Situacao: Realizado Justificativa: -- | |
*** | |
*** | |
Empresa: GOL Numero do voo: 3098 DI: 0 Tipo: N Origem: SBCG Destino: SBBR | |
Saida prevista: 10/02/14 10:15:10 | |
Saida real: 10/02/14 10:15:10 | |
Chegada prevista: 10/02/14 13:11:00 | |
Chegada real: 10/02/14 13:30:00 | |
Situacao: Realizado Justificativa: AA | |
*** | |
*** | |
Empresa: TAM Numero do voo: 3201 DI: 0 Tipo: R Origem: SBBR Destino: SBCG | |
Saida prevista: 10/02/14 10:15:10 | |
Saida real: 10/02/14 10:15:10 | |
Chegada prevista: 10/02/14 13:11:00 | |
Chegada real: 10/02/14 13:30:00 | |
Situacao: Realizado Justificativa: AA | |
*** | |
*** | |
Empresa: GOL Numero do voo: 4291 DI: 0 Tipo: R Origem: SBEG Destino: SBBR | |
Saida prevista: 11/02/14 19:15:10 | |
Saida real: 11/02/14 19:15:10 | |
Chegada prevista: 11/02/14 23:00:00 | |
Chegada real: 11/02/14 23:00:00 | |
Situacao: Realizado Justificativa: -- | |
*** | |
*** | |
Empresa: AZU Numero do voo: 4292 DI: 0 Tipo: R Origem: SBEG Destino: SBCG | |
Saida prevista: 11/02/14 19:40:00 | |
Saida real: 11/02/14 19:40:00 | |
Chegada prevista: 11/02/14 23:30:00 | |
Chegada real: 11/02/14 23:51:00 | |
Situacao: Realizado Justificativa: AJ | |
*** |
This file contains 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
[ | |
{ | |
"empresa": "TAM", | |
"voo": "3001", | |
"di": "0", | |
"tipo": "N", | |
"destino": "SBEG", | |
"justificativa": [ | |
{ | |
"destino2": "SBKP", | |
"saidaprev_data": "10/02/14", | |
"saidaprev_hora": "10:10:10", | |
"saidareal_data": "10/02/14", | |
"saidareal_hora": "10:10:10", | |
"chegadaprev_data": "10/02/14", | |
"chegadaprev_hora": "13:11:00", | |
"chegadareal_data": "10/02/14", | |
"chegadareal_hora": "13:11:00", | |
"situacao": "Situacao: Realizado" | |
} | |
] | |
}, | |
{ | |
"empresa": "GOL", | |
"voo": "3098", | |
"di": "0", | |
"tipo": "N", | |
"destino": "SBCG", | |
"justificativa": [ | |
{ | |
"destino2": "SBBR", | |
"saidaprev_data": "10/02/14", | |
"saidaprev_hora": "10:15:10", | |
"saidareal_data": "10/02/14", | |
"saidareal_hora": "10:15:10", | |
"chegadaprev_data": "10/02/14", | |
"chegadaprev_hora": "13:11:00", | |
"chegadareal_data": "10/02/14", | |
"chegadareal_hora": "13:30:00", | |
"situacao": "Situacao: Realizado" | |
} | |
] | |
}, | |
{ | |
"empresa": "TAM", | |
"voo": "3201", | |
"di": "0", | |
"tipo": "R", | |
"destino": "SBBR", | |
"justificativa": [ | |
{ | |
"destino2": "SBCG", | |
"saidaprev_data": "10/02/14", | |
"saidaprev_hora": "10:15:10", | |
"saidareal_data": "10/02/14", | |
"saidareal_hora": "10:15:10", | |
"chegadaprev_data": "10/02/14", | |
"chegadaprev_hora": "13:11:00", | |
"chegadareal_data": "10/02/14", | |
"chegadareal_hora": "13:30:00", | |
"situacao": "Situacao: Realizado" | |
} | |
] | |
}, | |
{ | |
"empresa": "GOL", | |
"voo": "4291", | |
"di": "0", | |
"tipo": "R", | |
"destino": "SBEG", | |
"justificativa": [ | |
{ | |
"destino2": "SBBR", | |
"saidaprev_data": "11/02/14", | |
"saidaprev_hora": "19:15:10", | |
"saidareal_data": "11/02/14", | |
"saidareal_hora": "19:15:10", | |
"chegadaprev_data": "11/02/14", | |
"chegadaprev_hora": "23:00:00", | |
"chegadareal_data": "11/02/14", | |
"chegadareal_hora": "23:00:00", | |
"situacao": "Situacao: Realizado" | |
} | |
] | |
}, | |
{ | |
"empresa": "AZU", | |
"voo": "4292", | |
"di": "0", | |
"tipo": "R", | |
"destino": "SBEG", | |
"justificativa": [ | |
{ | |
"destino2": "SBCG", | |
"saidaprev_data": "11/02/14", | |
"saidaprev_hora": "19:40:00", | |
"saidareal_data": "11/02/14", | |
"saidareal_hora": "19:40:00", | |
"chegadaprev_data": "11/02/14", | |
"chegadaprev_hora": "23:30:00", | |
"chegadareal_data": "11/02/14", | |
"chegadareal_hora": "23:51:00", | |
"situacao": "Situacao: Realizado" | |
} | |
] | |
} | |
] |
This file contains 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 file = require('fs'), | |
readline = require('readline'), | |
stream = require('stream'), | |
teste = require('./teste'), | |
express = require('express'), | |
app = express(); | |
app.route('/').get(function(req, res){ | |
res.send('Index'); | |
}); | |
app.listen(3000, function(){ | |
var instream = file.createReadStream('./aero.min.db'), | |
outstream = new stream, | |
rl2 = readline.createInterface(instream, outstream), | |
texto = ""; | |
console.log('Realizando leitura...'); | |
rl2.on('line', function(line) { | |
texto += line + "\n"; | |
}).on('close', function() { | |
console.log('Arquivo Lido com Sucesso!'); | |
teste.tratar(texto); | |
}); | |
}); |
This file contains 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 fs = require('fs'); | |
exports.tratar = function(text){ | |
var bd = [], bdoficial = [], cont= 0, cont2=0; | |
bd = text.split("***"); | |
bd.forEach(function(item){ | |
var aux = item.split('\t')[5], | |
valor = item.split('\t')[0]; | |
if(cont % 2 == 1){ | |
aux = aux.split('\n'); | |
valor = valor.split('\n'); | |
bdoficial[cont2] = { | |
empresa: (valor[1].split(' '))[1], | |
voo: ((item.split('\t')[1]).split(' '))[3], | |
di: ((item.split('\t')[2]).split(' '))[1], | |
tipo: ((item.split('\t')[3]).split(' '))[1], | |
destino: ((item.split('\t')[4]).split(' '))[1], | |
justificativa: [{ | |
destino2: (aux[0].split(' '))[1], | |
saidaprev_data: (aux[1].split(' '))[2], | |
saidaprev_hora: (aux[1].split(' '))[3], | |
saidareal_data: (aux[2].split(' '))[2], | |
saidareal_hora: (aux[2].split(' '))[3], | |
chegadaprev_data: (aux[3].split(' '))[2], | |
chegadaprev_hora: (aux[3].split(' '))[3], | |
chegadareal_data: (aux[4].split(' '))[2], | |
chegadareal_hora: (aux[4].split(' '))[3], | |
situacao: aux[5] | |
}] | |
}; | |
cont2++; | |
} | |
cont++; | |
}); | |
fs.writeFile("bd.json",JSON.stringify(bdoficial, null, 4), function(err) { | |
if(err) { | |
console.log(err); | |
} else { | |
console.log("The file was saved!"); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment