-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (33 loc) · 1020 Bytes
/
index.js
File metadata and controls
41 lines (33 loc) · 1020 Bytes
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
var request = require('request'),
cheerio = require('cheerio'),
_ = require('lodash'),
Promise = require('bluebird');
function pProfanityWords() {
var letters = _.map(new Array(26), function(value, index) {
return String.fromCharCode('a'.charCodeAt(0) + index);
});
var wordsPs = _.map(letters, function(letter) {
return new Promise(function(resolve, reject) {
request('http://www.noswearing.com/dictionary/' + letter,
function(err, res, body) {
if (err) return reject(err);
var $ = cheerio.load(body);
var words = $('center > div > table td:nth-child(1) b')
.map(function(i, el) {
var word = $(el).text();
return word;
}).toArray();
return resolve(words);
});
});
});
return Promise.all(wordsPs)
.then(function(wordsLists) {
return _.flatten(wordsLists);
});
}
if (module.parent) {
return pProfanityWords;
} else {
pProfanityWords().then(console.log.bind(console)).done();
}