SHOW:
|
|
- or go back to the newest paste.
| 1 | "use strict"; | |
| 2 | ||
| 3 | require("babel-core/register");
| |
| 4 | ||
| 5 | import fetch from "node-fetch"; | |
| 6 | import striptags from 'striptags'; | |
| 7 | import co from 'co'; | |
| 8 | ||
| 9 | const keyWords = ["butthurt", "бугурт", "буггурт", "баттхерт", "батхерт"]; | |
| 10 | ||
| 11 | let checkCaps = (str) => striptags(str).toUpperCase() === str; | |
| 12 | let checkDogs = (str) => (str.match(/\@/g) || []).length > 0; | |
| 13 | ||
| 14 | let detectButthurt = (thread) => {
| |
| 15 | let expr = new RegExp(keyWords.join("|"));
| |
| 16 | let dogsOut = checkDogs(thread.comment); | |
| 17 | let capsOn = checkCaps(thread.comment); | |
| 18 | let subjContainsKw = expr.test(thread.subject.toLowerCase()); | |
| 19 | ||
| 20 | return subjContainsKw || capsOn || dogsOut; | |
| 21 | }; | |
| 22 | ||
| 23 | let fetchThreadsLight = function*(url) {
| |
| 24 | let response = yield fetch(url); | |
| 25 | let parsedResponse = yield response.json(); | |
| 26 | console.log('total threads recieved: ' + parsedResponse.threads.length);
| |
| 27 | return parsedResponse.threads; | |
| 28 | }; | |
| 29 | ||
| 30 | let findSuspiciousThreads = (threads) => {
| |
| 31 | let suspiciousThreads = []; | |
| 32 | ||
| 33 | for (let thread of threads) {
| |
| 34 | let butthurtDetected = detectButthurt(thread); | |
| 35 | if (butthurtDetected) {
| |
| 36 | suspiciousThreads.push(thread); | |
| 37 | console.log('------------------');
| |
| 38 | console.log(thread.views); | |
| 39 | //console.log('link: ' + 'http://2ch.hk/b/res/' + thread.num + '.html');
| |
| 40 | console.log('------------------');
| |
| 41 | } | |
| 42 | } | |
| 43 | return suspiciousThreads; | |
| 44 | }; | |
| 45 | ||
| 46 | let run = function*() {
| |
| 47 | let threads = []; | |
| 48 | ||
| 49 | try {
| |
| 50 | // threads w/o posts | |
| 51 | threads = yield * fetchThreadsLight("http://2ch.hk/b/threads.json");
| |
| 52 | } catch (e) {
| |
| 53 | console.log('threads fetch failed');
| |
| 54 | } | |
| 55 | ||
| 56 | return findSuspiciousThreads(threads); | |
| 57 | }; | |
| 58 | ||
| 59 | co(run).then( | |
| 60 | suspiciousThreads => {
| |
| 61 | console.log('suspicious threads: ' + suspiciousThreads.length);
| |
| 62 | }, | |
| 63 | error => {
| |
| 64 | console.log(error); | |
| 65 | } | |
| 66 | ); |