-
Notifications
You must be signed in to change notification settings - Fork 0
/
postToServer.js
56 lines (50 loc) · 1.52 KB
/
postToServer.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var config = require('config');
var request = require('request');
var jsonfile = require('jsonfile');
var fs = require('fs');
var Logger = require("./Logger.js");
var host = config.get('server.host');
var port = config.get('server.port');
var serverUrl = host + ':' + port;
var apiBasePath = config.get('server.api');
const FILES_PATH = __dirname + "/scrapping/out/";
function ressponse_callback(error, response, body) {
if (!error && response.statusCode == 200) {
Logger.info(body);
} else {
console.log(error);
}
}
module.exports = function() {
var excludes = ".old";
var inputs = {
"events": "Calendar.json",
"news": "News.json",
"exams": /ExamDates.*\.json/
};
/*
* We are making POST to urls such us:
* server/api/load/courses
*
*/
for (var collecionName in inputs) {
var fileRegexp = inputs[collecionName];
fs.readdirSync(FILES_PATH).forEach(function(file) {
if (file.match(fileRegexp) !== null && !file.match(excludes)) {
var data = jsonfile.readFileSync(FILES_PATH + file);
console.log("Posting " + file);
request(
{
url: "http://" + serverUrl + apiBasePath + collecionName,
method: 'POST',
json: true,
body: data
},
ressponse_callback
);
}
});
}
}
doPost = module.exports;
doPost();