├── .gitignore ├── readme.md ├── package.json └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | bnw* 2 | node_modules 3 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ### Juice of the BnW 2 | 3 | Before all you have to clone the repo and install dependencies: 4 | 5 | ```bash 6 | git clone https://github.com/border-radius/bnwjuice 7 | cd bnwjuice 8 | npm install 9 | ``` 10 | 11 | Finally, you can squeeze the autism: 12 | 13 | ```bash 14 | npm start 15 | ``` -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bnwjuice", 3 | "version": "1.0.1", 4 | "description": "Juice of BNW", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index.js || nodejs index.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "author": "borde-radius", 11 | "license": "Unlicense", 12 | "dependencies": { 13 | "async": "^1.2.0", 14 | "request": "^2.57.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var request = require('request'); 2 | var async = require('async'); 3 | var fs = require('fs'); 4 | 5 | var file = 'bnw-' + new Date().getTime() + '.txt'; 6 | 7 | console.log('Writing to the file: ' + file); 8 | 9 | var queue = async.queue(function (url, next) { 10 | 11 | if (typeof url === 'number') { 12 | queue.push(url + 1); 13 | url = 'https://bnw.im/api/show?page=' + url; 14 | } else { 15 | url = 'https://bnw.im/api/show?replies=1&message=' + url; 16 | } 17 | 18 | request({ 19 | url: url, 20 | json: true 21 | }, function (error, response, json) { 22 | console.log('Fetched', url); 23 | 24 | if (!error && response.statusCode !== 200) { 25 | error = new Error('HTTP ' + response.statusCode + ': ' + url); 26 | } 27 | 28 | if (error) { 29 | console.error('>', error); 30 | return next(); 31 | } 32 | 33 | var text = []; 34 | 35 | if (json.messages) { 36 | text = json.messages.map(function (message) { 37 | queue.push(message.id); 38 | return message.tags.join(' ') + '\n' + message.text; 39 | }); 40 | } else if (json.replies) { 41 | text = json.replies.map(function (reply) { 42 | return reply.text; 43 | }); 44 | } else { 45 | console.log('No data found:', url); 46 | } 47 | 48 | fs.appendFile(file, text.join('\n\n'), { 49 | encoding: 'utf8' 50 | }, next); 51 | }); 52 | }, 10); 53 | 54 | queue.push(1); --------------------------------------------------------------------------------