Created
July 7, 2015 20:16
-
-
Save lemoogle/32c6856605517cc07eef to your computer and use it in GitHub Desktop.
Turn your Sphero into a twitter watchbot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Cylon = require('cylon'); | |
var Twitter = require('twitter'); | |
var iod = require('iod-node') | |
var iodclient= new iod.IODClient('http://api.idolondemand.com','<yourapikey>') | |
var twitterclient = new Twitter({ | |
consumer_key: '<yourconsumerkey>', | |
consumer_secret: '<yourconsumersecret>', | |
access_token_key: '<youraccesstoken>', | |
access_token_secret: '<youraccesstokensecret>' | |
}); | |
function watchdog(my){ | |
twitterclient.stream('statuses/filter', {track: 'sphero'}, function(stream) { | |
stream.on('data', function(tweet) { | |
var data= {'text':tweet.text} | |
iodclient.call('analyzesentiment',function(err,resp,body){ | |
var sentiment = body["aggregate"]["sentiment"]; | |
my.sphero.setHeading(0) | |
my.sphero.roll(0,180) // Everytime the sphero will spin half a rotation | |
if (sentiment=="positive"){ my.sphero.setRGB(0x01DF74) } //Green | |
else if (sentiment == "negative"){ my.sphero.setRGB(0xFF3300) } //Red | |
else{ my.sphero.setRGB(0x0066FF) } //Blue for neutral | |
after((1).seconds(), function() { // Return to white | |
my.sphero.setRGB(0xFFFFFF) | |
}); | |
},data) | |
}); | |
stream.on('error', function(error) { | |
throw error; | |
}); | |
}); | |
} | |
a=Cylon.robot({ | |
connections: { | |
sphero: { adaptor: 'sphero', port: '/dev/cu.Sphero-YBW-AMP-SPP' } | |
}, | |
devices: { | |
sphero: { driver: 'sphero' } | |
}, | |
work: watchdog | |
}); | |
b=a.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment