From b375cf9e933061f4177d743e9c9a02bcc94eff78 Mon Sep 17 00:00:00 2001 From: vitor-costa Date: Thu, 4 Dec 2014 13:50:19 -0200 Subject: [PATCH] api to get old jsons --- report.js | 37 ++++++++++++++++++++++++++++++------- riobus-config.json | 6 +++--- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/report.js b/report.js index 7221512..0ca9cc7 100644 --- a/report.js +++ b/report.js @@ -2,19 +2,42 @@ var express = require('express') var fs = require('fs') var app = express() -app.get('/', function (req, res) { +app.get('/api/:min_date/:max_date', function (req, res) { var min_date = req.param('min_date'); // YYYMMDDHH var max_date = req.param('max_date'); // YYYMMDDHH - var allfiles = fs.readdirSync(__dirname + "/files/").sort(); + console.log(min_date + "-" + max_date); + + var allFiles = fs.readdirSync(__dirname + "/files/").sort(); + console.log(allFiles); var files_to_use = []; - var l = allfiles.length; - var response = ""; + var l = allFiles.length; + + console.log(l); + + // removes the .json from file name + var allFilesName = allFiles.map(function(str) { + return str.split(".")[0]; + }); + + var response = "["; for (var i = 0; i < l; i++) { - if (allfiles[i] >= min_date && allfiles[i] <= max_date) { - response += fs.readFileSync(__dirname + "/files/" + allfiles[i]) + "\n"; + if (allFilesName[i] >= min_date && allFilesName[i] <= max_date) { + + // concatenates ',' for next json + if (response != "[") { + response += ","; + } + + response += fs.readFileSync(__dirname + "/files/" + allFiles[i]) + "\n"; } }; + response += "]"; + + res.send(response); + +}) +app.use(express.static(__dirname + '/public')); -}) \ No newline at end of file +var server = app.listen(3002); \ No newline at end of file diff --git a/riobus-config.json b/riobus-config.json index c7de5c9..5660c21 100644 --- a/riobus-config.json +++ b/riobus-config.json @@ -1,8 +1,8 @@ { "dataQueuer": { - "host": "riob.us", + "host": "rest.riob.us", "path": "/all", - "port": 81, - "intervalTime": 60000 + "port": 80, + "intervalTime": 10000 } } \ No newline at end of file