-
Notifications
You must be signed in to change notification settings - Fork 6
/
report.js
41 lines (30 loc) · 1010 Bytes
/
report.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var express = require('express')
var fs = require('fs')
var app = express()
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
console.log(min_date + "-" + max_date);
var allFiles = fs.readdirSync(__dirname + "/files/").sort();
console.log(allFiles);
var files_to_use = [];
var l = allFiles.length;
// 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 (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.jsonp(JSON.parse(response));
})
app.use(express.static(__dirname + '/public'));
var server = app.listen(3002);