Last active
September 15, 2017 15:54
-
-
Save adityathebe/ecd40ec28e1226e4a89b911120e2df9e to your computer and use it in GitHub Desktop.
Twitter Bot Final File
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
const TWIT = require('twit') | |
const config = require('./config'); | |
var Twit = new TWIT(config); | |
function makeTweet(tweet) { | |
Twit.post('statuses/update', { status: tweet }, function(err, data, response) { | |
if(err) { | |
console.log(err) | |
} else { | |
console.log("Tweet Made Successfully") | |
} | |
}); | |
}; | |
function favoriteTweet(tweet_id) { | |
Twit.post('favorites/create', {id: tweet_id}, function(err, data, response) { | |
if (err) { | |
console.log("Couldn't favorite tweet"); | |
} else { | |
console.log('Successfully favorited Tweet!'); | |
} | |
}); | |
} | |
function trackTweet(keyword) { | |
let stream = Twit.stream('statuses/filter', {track: keyword}) | |
stream.on('tweet', function (tweet) { | |
console.log(tweet.user.screen_name, 'tweeted', tweet.text); | |
favoriteTweet(tweet.id_str) | |
}); | |
} | |
function followUser(username) { | |
Twit.post('friendships/create', {screen_name: username}, function(err, data, response) { | |
if (err) { | |
console.log("Couldn't Follow!"); | |
} else { | |
console.log('Followed!', tweet.user.screen_name); | |
} | |
}); | |
} | |
trackTweet('nepal'); | |
// setInterval(makeTweet, 60 * 1000, Math.random() * 20) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment