Skip to content

Instantly share code, notes, and snippets.

@hopkira
Created November 6, 2017 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hopkira/210746ff118272e4f38a073108193049 to your computer and use it in GitHub Desktop.
Save hopkira/210746ff118272e4f38a073108193049 to your computer and use it in GitHub Desktop.
Simple flow that displays the location and sentiment of tweets on a world map

Demonstration flow for use on IBM Cloud. It should be pasted into editor of a Boilerplate Node-RED Starter container. It uses the pre-installed 'twitter-in' and 'sentiment' nodes along with the 'node-red-contrib-web-worldmap' nodes. These are likely to need to be installed separately using the Manage Palette capability or your preferred approach.

The application displays the location and sentiment of tweets for any topic, user or both at the /worldmap URL directly below the IBM Cloud hostname (i.e. https://example.ibm.host/worldmap).

The flow has been carefully crafted to be as simple as possible, so it is understandable and build-able by non-coders (indeed it was built for an executive audience). It makes no use of JavaScript function nodes.

Users should modify the 'twitter-in' node for any topic they like in the 'for' box. They should also create and paste in a Google API key from here https://developers.google.com/maps/documentation/geocoding/get-api-key into the indicated 'change' node.

Should the user be using free Google and IBM services and want to use the application for a long time, then it may be advisable to restrict the flow using a 'delay' node to send 1 message sent to Google every 35 seconds.

Full details, a build walkthrough and screenshots are in my blog here

[
{
"id": "a7d56879.7d1698",
"type": "twitter in",
"z": "402df9ce.b1eb88",
"twitter": "",
"tags": "ChangeMe",
"user": "false",
"name": "Change the 'for' value to choose what to follow",
"topic": "tweets",
"inputs": 0,
"x": 195.5,
"y": 41,
"wires": [
[
"e562b608.49cb78"
]
]
},
{
"id": "e562b608.49cb78",
"type": "change",
"z": "402df9ce.b1eb88",
"name": "Add your Google API key here",
"rules": [
{
"t": "set",
"p": "key",
"pt": "msg",
"to": "ADDYOURKEYHERE",
"tot": "str"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "tweet",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 207.5,
"y": 93.75,
"wires": [
[
"4b393414.bef15c"
]
]
},
{
"id": "4b393414.bef15c",
"type": "http request",
"z": "402df9ce.b1eb88",
"name": "Google Geocode Request",
"method": "GET",
"ret": "obj",
"url": "https://maps.googleapis.com/maps/api/geocode/json?address={{{location.place}}},+CA&key={{{key}}}&format=json",
"tls": "",
"x": 242.5,
"y": 144.75,
"wires": [
[
"fd796669.fc5f2"
]
]
},
{
"id": "fd796669.fc5f2",
"type": "change",
"z": "402df9ce.b1eb88",
"name": "Payload for sentiment",
"rules": [
{
"t": "set",
"p": "store.lat",
"pt": "msg",
"to": "payload.results[0].geometry.location.lat",
"tot": "msg"
},
{
"t": "set",
"p": "store.lon",
"pt": "msg",
"to": "payload.results[0].geometry.location.lng",
"tot": "msg"
},
{
"t": "set",
"p": "store.place",
"pt": "msg",
"to": "location.place",
"tot": "msg"
},
{
"t": "set",
"p": "store.name",
"pt": "msg",
"to": "tweet.id_str",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "tweet.text",
"tot": "msg"
},
{
"t": "set",
"p": "store.sender",
"pt": "msg",
"to": "tweet.user.screen_name",
"tot": "msg"
},
{
"t": "set",
"p": "store.photoUrl",
"pt": "msg",
"to": "tweet.user.profile_image_url",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 277,
"y": 191,
"wires": [
[
"1197af45.da0aa9"
]
]
},
{
"id": "1197af45.da0aa9",
"type": "sentiment",
"z": "402df9ce.b1eb88",
"name": "",
"x": 373.5,
"y": 239.5,
"wires": [
[
"98d3a4ba.f355a8"
]
]
},
{
"id": "98d3a4ba.f355a8",
"type": "change",
"z": "402df9ce.b1eb88",
"name": "Create payload for map",
"rules": [
{
"t": "set",
"p": "store.text",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "store.sentiment",
"pt": "msg",
"to": "sentiment.score",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "store",
"tot": "msg"
},
{
"t": "set",
"p": "payload.icon",
"pt": "msg",
"to": "fa-twitter-square",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 445,
"y": 285,
"wires": [
[
"f44a5c5b.817ef8"
]
]
},
{
"id": "a00343ff.43b138",
"type": "debug",
"z": "402df9ce.b1eb88",
"name": "Payload",
"active": true,
"console": "false",
"complete": "payload",
"x": 792,
"y": 567.8125,
"wires": []
},
{
"id": "95be1bb5.e769e8",
"type": "worldmap",
"z": "402df9ce.b1eb88",
"name": "",
"lat": "",
"lon": "",
"zoom": "",
"layer": "",
"cluster": "",
"maxage": "",
"usermenu": "show",
"layers": "show",
"panit": "false",
"x": 832.8609619140625,
"y": 477.25701904296875,
"wires": []
},
{
"id": "f44a5c5b.817ef8",
"type": "switch",
"z": "402df9ce.b1eb88",
"name": "Sentiment colour",
"property": "payload.sentiment",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "0",
"vt": "num"
},
{
"t": "gt",
"v": "0",
"vt": "str"
},
{
"t": "lt",
"v": "0",
"vt": "str"
}
],
"checkall": "true",
"outputs": 3,
"x": 524.263671875,
"y": 338.25,
"wires": [
[
"ad5d336f.4a6b6"
],
[
"e7942e4e.2e55"
],
[
"71aac55e.a12adc"
]
],
"inputLabels": [
"sentiment"
],
"outputLabels": [
"neutral",
"postive",
""
]
},
{
"id": "ad5d336f.4a6b6",
"type": "change",
"z": "402df9ce.b1eb88",
"name": "Set to grey",
"rules": [
{
"t": "set",
"p": "payload.iconColor",
"pt": "msg",
"to": "grey",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 626.763671875,
"y": 398,
"wires": [
[
"95be1bb5.e769e8",
"a00343ff.43b138"
]
]
},
{
"id": "e7942e4e.2e55",
"type": "change",
"z": "402df9ce.b1eb88",
"name": "Set to green",
"rules": [
{
"t": "set",
"p": "payload.iconColor",
"pt": "msg",
"to": "green",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 626.388671875,
"y": 440.5625,
"wires": [
[
"95be1bb5.e769e8",
"a00343ff.43b138"
]
]
},
{
"id": "71aac55e.a12adc",
"type": "change",
"z": "402df9ce.b1eb88",
"name": "Set to red",
"rules": [
{
"t": "set",
"p": "payload.iconColor",
"pt": "msg",
"to": "red",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 618.388671875,
"y": 486.3125,
"wires": [
[
"95be1bb5.e769e8",
"a00343ff.43b138"
]
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment