Analyzing Election Tweets

Sentiment Analysis on tweets with presidential candidate hashtags. Data sent to Initial State API for visualization.

[{"id":"9cddaeeb.738a4","type":"twitter in","z":"64da187d.4a1658","twitter":"","tags":"#trump","user":"false","name":"#trump","topic":"tweets","inputs":1,"x":159.99999237060547,"y":208.00002920627594,"wires":[["3f3d4414.156f1c"]]},{"id":"3f3d4414.156f1c","type":"sentiment","z":"64da187d.4a1658","name":"","x":352.66666412353516,"y":362.66669178009033,"wires":[["b061f52c.75d2d8"]]},{"id":"b061f52c.75d2d8","type":"switch","z":"64da187d.4a1658","name":"","property":"sentiment.score","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"str"},{"t":"eq","v":"0","vt":"str"},{"t":"lt","v":"0","vt":"str"}],"checkall":"false","outputs":3,"x":580.3333740234375,"y":259.6667079925537,"wires":[["13b54474.c494ac"],["c8818202.3b84f"],["7ae37329.a3dbdc"]]},{"id":"13b54474.c494ac","type":"function","z":"64da187d.4a1658","name":"Positive Score","func":"msg.payload = '{\"tscore\" :' + msg.sentiment.score +\"}\";\nreturn msg;","outputs":1,"noerr":0,"x":754.0000152587891,"y":168.66669464111328,"wires":[["255c7f7e.5c5b2","7b81c675.68e688","bf431f8.61be1e"]]},{"id":"c8818202.3b84f","type":"function","z":"64da187d.4a1658","name":"Neutral Score","func":"msg.payload = '{\"tscore\" :' + msg.sentiment.score +\"}\";\nreturn msg;","outputs":1,"noerr":0,"x":771.6666564941406,"y":261.0000286102295,"wires":[["255c7f7e.5c5b2","bf431f8.61be1e","7b81c675.68e688"]]},{"id":"7ae37329.a3dbdc","type":"function","z":"64da187d.4a1658","name":"Negative Score","func":"msg.payload = '{\"tscore\" :' + msg.sentiment.score +\"}\";\nreturn msg;","outputs":1,"noerr":0,"x":760.6666870117188,"y":328.0000305175781,"wires":[["255c7f7e.5c5b2","bf431f8.61be1e","7b81c675.68e688"]]},{"id":"c91755a3.afdb68","type":"twitter in","z":"64da187d.4a1658","twitter":"","tags":"#hillary","user":"false","name":"#hillary","topic":"tweets","inputs":1,"x":149.66665649414062,"y":473.0000305175781,"wires":[["51d77998.2aadb8"]]},{"id":"51d77998.2aadb8","type":"sentiment","z":"64da187d.4a1658","name":"","x":377.6666564941406,"y":612.0000286102295,"wires":[["29c574c1.c2f35c"]]},{"id":"29c574c1.c2f35c","type":"switch","z":"64da187d.4a1658","name":"","property":"sentiment.score","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"str"},{"t":"eq","v":"0","vt":"str"},{"t":"lt","v":"0","vt":"str"}],"checkall":"false","outputs":3,"x":568.6666564941406,"y":514.0000286102295,"wires":[["81b52c14.c18b7"],["fa443302.a585e"],["1a052eb8.261ca1"]]},{"id":"255c7f7e.5c5b2","type":"debug","z":"64da187d.4a1658","name":"","active":false,"console":"false","complete":"false","x":1086.4285736083984,"y":85.23809814453125,"wires":[]},{"id":"bf431f8.61be1e","type":"ibmiot out","z":"64da187d.4a1658","authentication":"boundService","apiKey":"","outputType":"evt","deviceId":"Tweet1","deviceType":"TwitterDevice","eventCommandType":"update","format":"json","data":"tweet","qos":0,"name":"IBM IoT","service":"registered","x":1077.8571434020996,"y":370.0000114440918,"wires":[]},{"id":"81b52c14.c18b7","type":"function","z":"64da187d.4a1658","name":"Positive Score","func":"msg.payload = '{\"hscore\" :' + msg.sentiment.score +\"}\";\nreturn msg;","outputs":1,"noerr":0,"x":756,"y":444,"wires":[["77668335.4bb4ac","36f37032.748da","18afcf75.bab361"]]},{"id":"fa443302.a585e","type":"function","z":"64da187d.4a1658","name":"Neutral Score","func":"msg.payload = '{\"hscore\" :' + msg.sentiment.score +\"}\";\nreturn msg;","outputs":1,"noerr":0,"x":747.6666259765625,"y":517.3333129882812,"wires":[["36f37032.748da","77668335.4bb4ac","18afcf75.bab361"]]},{"id":"1a052eb8.261ca1","type":"function","z":"64da187d.4a1658","name":"Negative Score","func":"msg.payload = '{\"hscore\" :' + msg.sentiment.score +\"}\";\nreturn msg;","outputs":1,"noerr":0,"x":756.6666870117188,"y":607.3333129882812,"wires":[["36f37032.748da","77668335.4bb4ac","18afcf75.bab361"]]},{"id":"36f37032.748da","type":"debug","z":"64da187d.4a1658","name":"","active":false,"console":"false","complete":"false","x":1033,"y":437,"wires":[]},{"id":"77668335.4bb4ac","type":"ibmiot out","z":"64da187d.4a1658","authentication":"boundService","apiKey":"","outputType":"evt","deviceId":"Tweet1","deviceType":"TwitterDevice","eventCommandType":"update","format":"json","data":"tweet","qos":0,"name":"IBM IoT","service":"registered","x":1080,"y":678.3333129882812,"wires":[]},{"id":"7b81c675.68e688","type":"function","z":"64da187d.4a1658","name":"Device payload trump","func":"\n\n \nvar dev_url = \"https://groker.initialstate.com/api/events\";\n\nvar data = { \"key\" : \"tscore\", \"value\" : msg.sentiment.score}\n\nvar msg = {\n    \"method\" : \"POST\",\n    \"url\" : dev_url,\n    \"headers\" : {\n        \"Content-Type\": \"application/json\",\n        \"X-IS-AccessKey\": \"yaoJReIXAXs2VMT1WeFtullCLtQj0riy\",\n        \"X-IS-BucketKey\" : \"Q8SVTP7AS8WR\",\n        \"Accept-Version\": \"0.0.1\"\n    },\n    \"payload\" : JSON.stringify(data)\n};\n \nreturn msg;","outputs":1,"noerr":0,"x":1174.2857666015625,"y":237.14285278320312,"wires":[["2674bc18.47b6c4","142c1bd2.c76204"]]},{"id":"689f7b84.4fe164","type":"debug","z":"64da187d.4a1658","name":"Debug output payload","active":false,"console":"false","complete":"payload","x":1602,"y":328,"wires":[]},{"id":"2674bc18.47b6c4","type":"http request","z":"64da187d.4a1658","name":"","method":"use","ret":"txt","url":"","tls":"","x":1406.5,"y":237,"wires":[["689f7b84.4fe164","313584ed.d570ec"]]},{"id":"313584ed.d570ec","type":"http response","z":"64da187d.4a1658","name":"","x":1566.5,"y":137,"wires":[]},{"id":"142c1bd2.c76204","type":"debug","z":"64da187d.4a1658","name":"Debug output payload","active":false,"console":"false","complete":"payload","x":1404,"y":50,"wires":[]},{"id":"18afcf75.bab361","type":"function","z":"64da187d.4a1658","name":"Device payload hillary","func":"\n\n \nvar dev_url = \"https://groker.initialstate.com/api/events\";\n\nvar data = { \"key\" : \"hscore\", \"value\" : msg.sentiment.score}\n\nvar msg = {\n    \"method\" : \"POST\",\n    \"url\" : dev_url,\n    \"headers\" : {\n        \"Content-Type\": \"application/json\",\n        \"X-IS-AccessKey\": \"yaoJReIXAXs2VMT1WeFtullCLtQj0riy\",\n        \"X-IS-BucketKey\" : \"Q8SVTP7AS8WR\",\n        \"Accept-Version\": \"0.0.1\"\n    },\n    \"payload\" : JSON.stringify(data)\n};\n \nreturn msg;","outputs":1,"noerr":0,"x":1071,"y":571,"wires":[["87d6a6d0.6f0b48","fcf8894c.ecfae8"]]},{"id":"87d6a6d0.6f0b48","type":"http request","z":"64da187d.4a1658","name":"","method":"use","ret":"txt","url":"","tls":"","x":1294.2142333984375,"y":650.8571472167969,"wires":[["b9b3ad10.c8ad1","5a0681ae.ac775"]]},{"id":"b9b3ad10.c8ad1","type":"http response","z":"64da187d.4a1658","name":"","x":1454.2142333984375,"y":550.8571472167969,"wires":[]},{"id":"fcf8894c.ecfae8","type":"debug","z":"64da187d.4a1658","name":"Debug output payload","active":true,"console":"false","complete":"payload","x":1291.7142333984375,"y":463.8571472167969,"wires":[]},{"id":"5a0681ae.ac775","type":"debug","z":"64da187d.4a1658","name":"Debug output payload","active":true,"console":"false","complete":"payload","x":1524,"y":651,"wires":[]}]

Flow Info

Created 8 years, 1 month ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x6)
  • function (x8)
  • http request (x2)
  • http response (x2)
  • switch (x2)
Other

Tags

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