-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest.js
34 lines (30 loc) · 1 KB
/
request.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
exports.requestPunctuatedText = function(callArray, keywordArray, onPunctuationComplete) {
"use strict";
var request = require('request');
function donePunctuating() {
console.log('all done');
console.log(punctuatedArray);
onPunctuationComplete(punctuatedArray);
}
var itemsProcessed = 0;
var punctuatedArray = [];
var sentencesWithKeywordsArray = [];
callArray.forEach(function(item, index, array){
// Configure the request
var options = {
url: 'http://bark.phon.ioc.ee/punctuator',
method: 'POST',
form: {'text': item}
};
// Set the headers and options ...
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
punctuatedArray.push(body);
itemsProcessed++;
if(itemsProcessed === array.length) {
donePunctuating();
}
}
});
});
};