CREATE TWITTER AUTO RETWEET BOT IN PYTHON

Twitter automatic Retweet/Favorite Bot in Nodejs

Be Different from others, thats what makes you yourself 

Let’s get started to make very first twitter bot which will retweet & favorite tweets. In this post I will help setting account and the retweet function
To get started we will need Nodejs(npm), it can be downloaded from here https://nodejs.org and install it
I'm going to use nodepad+ editor (You can use any editor available.)

Twitter Developer Account
Goto https://developer.twitter.com and create a new app, now give the name of the app, that can be anything for just completing the steps, in website input box enter Facebook or Gmail or any website, twitter has no concern about it.


Keys and Tokens

Now make a new file called config.js and in it paste these tokens and keys like
module.exports = {
consumer_key:' ',
consumer_secret:' ',
access_token:' ',
access_token_secret:' '
}

config.js


Go to your terminal or command line, open the folder where this config.js file is stored and write
npm init -y
It will create package.json file in that folder. 
Let us now install twit, the package we will use in our coding, again in the command line
npm install  --save twit
Now open package.json file, it should have the twit dependency.

package.json


Now create a new file with name bot.js 
Copy the below code in the newly created file(bot.js)
const config=require('./config')
const twit=require('twit')
const T=new twit(config)
console.log("Tavan Champaneri's Twitter Bot Started");
function retweet()
{
let params={
q:'#HashtagToRetweet/Favorite min_retweets:20 lang:en',
result_type:'recent',
count:100
}
T.get('search/tweets', params,(err,data,response)=>
{
let tweets=data.statuses
if(!err)
{
for(let dat of tweets)
{
let retweetId = dat.id_str;
T.post('statuses/retweet/:id', {id: retweetId}, (err, response)=>
{
if (response)
console.log('Post retweeted!!! with retweetID - ' + retweetId)
if (err)
console.log('Already RETWEETED...')
})}}})}
setInterval(retweet,60000)
Now in command line, run the program by node bot.js


@TavanChampaneri

Check complete YouTube video here



Comment

Previous Post Next Post