-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
66 lines (59 loc) · 1.85 KB
/
index.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
57
58
59
60
61
62
63
64
65
66
const request = require('request');
const _ = require('underscore');
const async = require('async');
const fs = require('fs');
const baseString = "abcdefghijklmnopqrstuvwxyz "; //specify the characters here to build your search string
const outputFileName = "output-" + new Date().getTime() + ".tsv";
var requestObject = {
url : "", //specifu url here
mehtod : "POST", //specify method here
json : true, //important
body : {
},
//encoding : null,
headers : {
}
}
function makeSearchCall(searchString, callback){
requestObject.body.searchTerm = searchString; //repalce the search term
console.log(searchString);
request.post(requestObject, function(error, response, body){
if(error){
console.error('Something went wrong');
console.error(error);
} else {
var data = "";
_.each(body, function(record){
data = data + record.key1 + "\t" +
record.key2 + "\t" +
record.key3 + "\t" +
"\n";
})
//console.log(data)
fs.appendFile("output/"+outputFileName , data, function (err) {
if (err) {
return console.error(err);
}
callback();
});
}
});
}
var searchLetters = [];
var alphabets = baseString.split("");
_.each(alphabets, function(a){
searchLetters.push(a);
_.each(alphabets, function(b){
searchLetters.push(a+b);
_.each(alphabets, function(c){
searchLetters.push(a+b+c);
//in case you want another level
// _.each(alphabets, function(d){
// searchLetters.push(a+b+c+d);
// });
});
})
})
//use this line in case the earlier job got stuck at some searchLetter
//searchLetters = searchLetters.splice(searchLetters.indexOf("tsw"), (searchLetters.length - searchLetters.indexOf("tsw")));
async.eachSeries(searchLetters, makeSearchCall, function(){console.log('done'); process.exit(0);});