Monday, 24 April 2017

Twitter bot coding to stream tweets

I am creating a twitter bot from a twit package (https://github.com/ttezel/twit) for a project I am working on, however I have never done programming before. I have attached what I have managed to do so far, which is getting the bot to search for a term in a geolocation. But what I am stuck on is how to create a stream for live tweets that I can turn on and off by entering a word in terminal. The link I have attached has some programming language to do a stream but I don't know where I would put this in to make it work. If anyone has any knowledge on how to do this I would greatly appreciated it, thank you!

This is the coding I have done:

console.log('The bot is starting');
var Twit = require('twit');
var config = require('./config');
var T = new Twit(config);

var params = {
q: 'racism',
geocode: '51.507,-0.128,100mi', 
count: 200

}

T.get('search/tweets', params, gotData);

function gotData(err, data, response) {
console.log(data);
}

This is the coding the package suggests to implement somewhere for a stream:

//
//  filter the twitter public stream by the word 'mango'.
//
var stream = T.stream('statuses/filter', { track: 'mango' })

stream.on('tweet', function (tweet) {
console.log(tweet)
})



via maria benedict

No comments:

Post a Comment