flow

something wrong

[{"id":"2e79fb74.d18604","type":"websocket-listener","path":"/ws/wordcloud","wholemsg":"false"},{"id":"971c3cb4.68e3c","type":"twitter in","twitter":"","tags":"Wimbledon","user":"false","name":"","topic":"tweets","x":95,"y":860,"z":"be2ce773.41d318","wires":[["82800f44.7d7ff","db1d2cd.f24e2d"]]},{"id":"db1d2cd.f24e2d","type":"function","name":"Filter Tweets","func":"\nvar tweets = context.tweets || [\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"];\n\nif (msg.tweet.lang == \"en\") {\n\n\tvar foo = msg.tweet.text;\n\tif (foo.indexOf(\"http\") != -1) {\n\t\tfoo = (foo.split(\"http\"))[0];\n\t}\n\tif (foo.toLowerCase().indexOf(\"job\") != -1) return null;\n\tfoo = foo.replace(/[^\\x00-\\x7F]/g, \"\");\n\t\n\tif (tweets.indexOf(foo) == -1) {\n\t\ttweets.shift();\n\t\ttweets.push(foo);\n\t\t//console.log(tweets);\n\t\tcontext.tweets = tweets;\n\t\treturn {payload:tweets};\n\t}\n}\nreturn null;\n","outputs":1,"x":231,"y":915,"z":"be2ce773.41d318","wires":[["a021049c.5fdef8"]]},{"id":"a021049c.5fdef8","type":"delay","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"12","rateUnits":"minute","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":338,"y":862,"z":"be2ce773.41d318","wires":[["ec4252b1.13bdb"]]},{"id":"ec4252b1.13bdb","type":"function","name":"Count words in array","func":"var index = {};\n\nvar garbage = [ \"and\", \"for\", \"but\", \"the\", \"&lt\", \"&gt\", \"his\", \"her\", \"pre\", \"are\", \"&amp\", \"with\", \"fuck\", \"shit\", \"crap\", \"cunt\"];\n\nfunction countWords(sentence) {\n\twords = sentence\n\t\t.replace(/[.,?!;()\"'-]/g, \" \")\n\t\t.replace(/\\s+/g, \" \")\n\t\t//.toLowerCase()\n\t\t.split(\" \");\n\t\n\twords.forEach(function (word) {\n\t\tif ((word.length > 2)&&( isNaN(Number(word)) )&&( garbage.indexOf(word.toLowerCase()) == -1 )) {\n\t\t if (!(index.hasOwnProperty(word))) {\n\t\t index[word] = 0;\n\t\t }\n\t\t index[word]++;\n\t\t}\n\t});\n\t\n\t//console.log(Object.keys(index).length);\n\t//return index;\n}\n\nfor (var i in msg.payload) {\n\tcountWords(msg.payload[i]);\n}\n\nmsg.payload = JSON.stringify(index);\n\nreturn msg;","outputs":1,"x":461,"y":918,"z":"be2ce773.41d318","wires":[["8d368567.72c978","ae9655e4.5169a8"]]},{"id":"8d368567.72c978","type":"websocket out","name":"","server":"2e79fb74.d18604","x":600,"y":850,"z":"be2ce773.41d318","wires":[]},{"id":"ae9655e4.5169a8","type":"debug","name":"","active":false,"console":"false","complete":"false","x":651,"y":918,"z":"be2ce773.41d318","wires":[]}]

Flow Info

Created 8 years, 7 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x1)
  • delay (x1)
  • function (x2)
  • websocket out (x1)
  • websocket-listener (x1)
Other

Tags

  • piko
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option