Skip to content

Instantly share code, notes, and snippets.

@epall
Created November 14, 2012 14:52
Show Gist options
  • Save epall/4072556 to your computer and use it in GitHub Desktop.
Save epall/4072556 to your computer and use it in GitHub Desktop.
Post tweets with a hashtag to an Electric Imp "Emma" board
var twitter = require('node-twitter')
, util = require('util')
, https = require('https')
var twitterClient = new twitter.SearchClient({
consumer_key: '__YOUR_TWITTER_CONSUMER_KEY__',
consumer_secret: '__YOUR_TWITTER_CONSUMER_SECRET__'
});
var lastTweet;
function getNextTweet() {
twitterClient.search({q: '#electricimptest'}, function(err, data) {
if(data && data.results) {
var recentTweet = data.results[0];
if(lastTweet != recentTweet.id_str) {
sendToEmma(recentTweet.text);
lastTweet = recentTweet.id_str;
}
}
setTimeout(getNextTweet, 1000);
});
}
function sendToEmma(text) {
text = text.replace(/#electricimptest/, '')
console.log(text);
var req = https.request({
host: 'api.electricimp.com',
port: 443,
path: '/v1/__PLAN_ID__/__HTTP_NODE_ID__?value='+encodeURIComponent(text),
method: 'GET'
}, function(response) {
});
req.end();
}
getNextTweet();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment