I’ve been using the Twitter stream code, and it works really well. Now, I would like to parse the entire returned tweet for other text. It looks like I can use split() like this: local tweetParsed = split(tweet.text, " ");
and get an array that I could check. Are there any better ways of doing this?
This seems to work: local tweetParsed = split(tweet.text, " "); foreach(string in tweetParsed) { if (string == "#Red"){ device.send("rgb", color_red); }
If you tweet using #Neopixel and a color, like: #Red#Green#Blue you’ll change the color of my Neopixel ring.
Hashtags are also returned as entities. Here’s some code you can use to loop through and log all of the hashtags in a tweet:
if ("entities" in tweet && "hashtags" in tweet.entities) { foreach(tag in tweet.entities.hashtags) { // do something interesting with hashtags server.log(tag.text); } }
You also get media things (images, videos, links, etc) and all kinds of other goodies.
If you search Twitter’s API documentation, you should be able to get a complete list of what can be returned from searches/streams/etc and how it looks.
Or pass your tweet object into the logTable function from this post