Sentiment Bowl

The Super Bowl is happening this afternoon in the San Francisco Bay Area. There’s going to be (already is) a lot of activity on social media, with fans rooting for their favorite team to win the trophy. Fans on Twitter usually choose to positively support their team with words of encouragement, or talk negatively to the other team.


So which team has the more positive fans? Seems like a pretty simple problem to figure out. I created simple web app I call the Sentiment Bowl using the positive tweets being made around the two twitter handles @broncos (Denver Broncos) and the @panthers (Carolina Panthers). Using the Insights for Twitter service on IBM Bluemix, the score is settled based on how many positive tweets each team is mentioned in. You can find the running application at


To get started, sign up for a free Bluemix account. Click on the Catalog link in the upper right corner of the dashboard.

We’ll use Node-RED, one of my favorite services in Bluemix because it has a graphical interface that makes prototyping quick and easy. Click on the Node-RED Starter under the Boilerplates section.


Give the application a name and a host. If you choose myapp, your application will be available at


The application will begin staging. Once it is running, click on the Overview link in the left sidebar. We want to add the Insights for Twitter service. Click on Add a Service or API.


Scroll down the catalog to the Data and Analytics section and choose the Insights for Twitter service.


Click on the Create button to create and bind the service to your application.


You’ll be prompted to restage the application. Click on Restage.


Once the application is running, click on Environment Variables. Copy the URL value under the twitterinsights.credentials.url property. Save this for later when we configure the application.


Visit the URL of your application. This is the homepage of Node-RED. Click on the red button labeled Go to your Node-RED flow editor.


On the left side is a palette of nodes that perform different actions. Some have a grey circle on the left, where you can connect inputs, and/or a grey circle on the right, where you connect outputs. Click and drag your cursor from output circles to input circles to create what are called flows.


To save you some time, you can import the nodes and the complete application. Click on the menu button in the top right corner. Click on Import and then Clipboard.


Copy the following JSON into the textbox:

[{"id":"5aeae2c1.f445cc","type":"inject","z":"4686641b.b9799c","name":"init","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":true,"x":153,"y":112,"wires":[["2dac8fd8.260108"]]},{"id":"9e50786.586cc88","type":"http request","z":"4686641b.b9799c","name":"","method":"GET","ret":"obj","url":"","x":417.5,"y":180,"wires":[["1cd41739.28a8f9"]]},{"id":"1cd41739.28a8f9","type":"function","z":"4686641b.b9799c","name":"","func":" = parseInt(;\n","outputs":1,"noerr":0,"x":588.5,"y":179.5,"wires":[[]]},{"id":"5c6649b9.b4ed8","type":"http request","z":"4686641b.b9799c","name":"","method":"GET","ret":"obj","url":"","x":416,"y":243.5,"wires":[["be20cbcb.312ab8"]]},{"id":"be20cbcb.312ab8","type":"function","z":"4686641b.b9799c","name":"","func":" = parseInt(;\n","outputs":1,"noerr":0,"x":586,"y":243,"wires":[[]]},{"id":"37bfe23b.c0e266","type":"function","z":"4686641b.b9799c","name":"","func":"return {\n    url:':443/api/v1/messages/count?q=''%20sentiment%3Apositive%20posted%3A'','\n}\n","outputs":1,"noerr":0,"x":268.5,"y":180,"wires":[["9e50786.586cc88"]]},{"id":"7b70c516.380f54","type":"inject","z":"4686641b.b9799c","name":"","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":true,"x":119.5,"y":180,"wires":[["37bfe23b.c0e266","ce7dcbc8.e820a8"]]},{"id":"5a803eb4.708c98","type":"http response","z":"4686641b.b9799c","name":"","x":734,"y":374,"wires":[]},{"id":"f44030b2.e6cfc8","type":"http in","z":"4686641b.b9799c","name":"","url":"/","method":"get","swaggerDoc":"","x":128,"y":374,"wires":[["e60c9676.ac66e8"]]},{"id":"ce7dcbc8.e820a8","type":"function","z":"4686641b.b9799c","name":"","func":"return {\n    url:':443/api/v1/messages/count?q=''%20sentiment%3Apositive%20posted%3A'','\n}\n","outputs":1,"noerr":0,"x":267.5,"y":242,"wires":[["5c6649b9.b4ed8"]]},{"id":"e60c9676.ac66e8","type":"function","z":"4686641b.b9799c","name":"","func":"msg.payload = {};\n\nif( > {\n    msg.payload.headline =' lead '' '+Math.max(,'-'+Math.min(,;\n    msg.payload.team1 =;\n} else if( < {\n    msg.payload.headline =' lead '' '+Math.max(,'-'+Math.min(,;\n    msg.payload.team1 =;\n} else {\n    msg.payload.headline =' tied '' at ';\n    msg.payload.team1 =;\n    msg.payload.team2 =;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":345,"y":374,"wires":[["8fda4fd2.3f95b"]]},{"id":"8fda4fd2.3f95b","type":"template","z":"4686641b.b9799c","name":"","field":"payload","fieldType":"msg","format":"handlebars","template":"<html>\n    <head>\n        <title>Sentiment Bowl 2016</title>\n        <style>\n            img { max-width: 200px }\n            body { font-family: Arial }\n        </style>\n    </head>\n    <body>\n        <center>\n            <h2>{{payload.headline}}</h2>\n            <img src=\"{{payload.team1}}\" />\n            {{#payload.team2}}\n                <img src=\"{{payload.team2}}\" />\n            {{/payload.team2}}\n            \n            \n        </center>\n        <footer style=\"position: absolute; bottom: 10px; text-align: center; width: 100%\">Powered by <a href=\"\" target=\"_blank\">Node-RED</a> running on <a href=\"\" target=\"_blank\">IBM Bluemix</a>, using <a href=\"\" target=\"_blank\">Insights for Twitter</a></footer>\n    </body>\n</html>","x":520,"y":374,"wires":[["5a803eb4.708c98"]]},{"id":"2dac8fd8.260108","type":"function","z":"4686641b.b9799c","name":"Set Config","func":" = '';\ = '2016-02-07T23:30:00Z';\ = '2016-02-08T03:30:00Z';\n\ = '@broncos';\ = 'Denver Broncos';\ = '';\n\ = '@panthers';\ = 'Carolina Panthers';\ = '';","outputs":1,"noerr":0,"x":357,"y":112,"wires":[[]]}]

Double click on the node labeled Set Config. Replace the URL in with the URL you copied earlier from the Environment Variables. This will use the Insights for Twitter Bluemix service you created earlier.


Click on Deploy and visit your application’s URL again. You should see a webpage similar to this.


You can customize the Twitter handles and the time range (change the value if the game goes into overtime and click Deploy to the save the changes). For the big game, I’ve used the kickoff time of 3:30 Pacific.

So who do you think will win the Sentiment bowl on Sunday?

This entry was posted in Projects. Bookmark the permalink.