This README file documents the deployment and usage of TwitterBot. This software was developed by Jacek Aleksander Gruca for Walter Roloson as part of their contract concluded electronically in May 2016.
TwitterBot is a bot that follows handles on a specified list according to the logic defined below.
- Follow handles on a specific list.
- Track when they were last followed.
- Not follow anyone followed in the past year.
- Not follow anyone already following my handle.
- Unfollow the person after 30 days.
- Process no more than 50 items in the queue per each invocation.
- If already following a person that is not following my handle and they have not been followed in the past year, unfollow them and then re-follow them in 30 days.
TwitterBot is implemented in Python 2.7. It makes use of MongoDB for persistence storage and interacts with the Twitter API.
- Make sure you have Python 2.7, python-dev/python-devel and pip installed.
- Execute the following commands:
pip install pandas
pip install tweepy
pip install pymongo
The configuration of TwitterBot is stored in file config.ini. This file contains descriptive comments so proceed there if you want to amend configuration.
You will need to set up a Twitter application. You can create one here: https://apps.twitter.com/. Once you have it created navigate to the "Keys and Access Tokens" section for your Consumer Key, Consumer Secret, Access Token and Access Token Secret. These items should be input into the config.ini file.
- Please follow the below commands. A useful resource to refer to is also: http://www.codexpedia.com/devops/mongodb-authentication-setting/.
- First install MongoDB by following the instructions for your operating system. We will assume you installed version 3.2. Ref. https://docs.mongodb.com/manual/installation/?jmp=footer&_ga=1.175002593.2134140820.1471180198
- Then enter the MongoDB shell by typing in the following in the command line:
$ mongo
- Execute the following commands.
use admin;
db.createUser(
{
user: "admin",
pwd: "adminPassword",
roles: [ { role: "root", db: "admin" } ]
}
);
exit;
- Shutdown your Mongo instance by following these instructions: http://stackoverflow.com/questions/11774887/how-to-stop-mongo-db-in-one-command.
- Locate your configuration file
mongod.conf
. It will be in /etc or /usr/local/etc or a similar directory. - Edit this file by appending the following lines to it at the bottom. This will disable passwordless login from your localhost workstation, and will always require a password to log in.
setParameter:
enableLocalhostAuthBypass: false
security:
authorization: enabled
- Start your mongo instance again.
$ mongod --config /path/to/your/config/file/mongod.conf
- Again enter the MongoDB shell by typing in the following in the command line.
$ mongo
- Execute the following commands.
use admin;
db.auth("admin", "adminPassword");
use twitterbot;
db.createUser(
{
user: "twitterbot",
pwd: "twitterbotPassword",
roles: [ { role: "dbAdmin", db: "twitterbot" }, { role: "readWrite", db: "twitterbot" } ]
}
);
exit;
- Then connect to your Mongo DB instance again (by typing
mongo
in the shell) and execute the following commands:
use twitterbot;
db.auth('twitterbot','twitterbotPassword');
db.createCollection('queue');
db.createCollection('allhandles');
db.queue.find();
db.allhandles.find();
exit;
-
The above commands validate yout MongoDB set up. If they fail, don't proceed further but instead try to identify which of the previous steps is causing the problem.
-
Finally set up your MongoDB URI in file config.ini.
In the command line enter the directory containing this README file and type:
$ python followHandles.py -h
This will output the usage details. The parameter to specify is an input CSV file with handles to be processed. This file should contain the following columns (same as sample file 'TwitterFollow-Walt.csv' provided):
- Name.
- Job.
- Title.
- Company.
- Linkedin.
- Twitter.
- SIQ.
- Notes.
- At the beginning TwitterBot will check whether the queue it maintains and the input list of handles is the same. If it is the same, it will proceed carrying out the logic described above. If there are differences between the queue and the list, it will take the following actions:
- Items in the input list, which are missing from the queue, will be added to the queue.
- Items in the queue, which are not in the input list, will be removed from the queue.
- Please note that any items being followed will not be unfollowed when removed from the queue in the above step. (This behaviour may be amended)
- TwitterBot is limited by Twitter API rate limits defined here https://dev.twitter.com/rest/public/rate-limits. This means that TwitterBot will pause after it has reached any of the limits and sleep for the required number of minutes before processing further.
The bot will probably be invoked once a day.
Similar publicly available projects are:
- https://pypi.python.org/pypi/TwitterFollowBot/v2.0
- https://github.com/rhiever/TwitterFollowBot
- https://github.com/ProgrammingforMarketers/grow-twitter-following
Please contact Jacek Aleksander Gruca with any issues, questions or comments.