Skip to content

Commit

Permalink
api to get old jsons
Browse files Browse the repository at this point in the history
  • Loading branch information
vitor-costa committed Dec 4, 2014
1 parent d124f8a commit b375cf9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
37 changes: 30 additions & 7 deletions report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

})
var server = app.listen(3002);
6 changes: 3 additions & 3 deletions riobus-config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"dataQueuer": {
"host": "riob.us",
"host": "rest.riob.us",
"path": "/all",
"port": 81,
"intervalTime": 60000
"port": 80,
"intervalTime": 10000
}
}

0 comments on commit b375cf9

Please sign in to comment.