Giter VIP home page Giter VIP logo

twitterfollowbot's Introduction

PyPI version Python 2.7 Python 3.5 License

Twitter Bot

Join the chat at https://gitter.im/rhiever/TwitterFollowBot

A Python bot that automates several actions on Twitter, such as following users and favoriting tweets.

Notice: Repository is no longer being maintained

Twitter has started cracking down heavily on users who use bots like this one to follow users or favorite tweets en masse. For that reason, I am no longer developing this code repository but will leave it up for anyone who wants to use it as a code base for future projects. Please respect the software license if you use the code from this repository.

Disclaimer

I hold no liability for what you do with this bot or what happens to you by using this bot. Abusing this bot can get you banned from Twitter, so make sure to read up on proper usage of the Twitter API.

Installation

You can install the Twitter Follow Bot using pip:

pip install TwitterFollowBot

Dependencies

You will need to install Python's python-twitter library:

pip install twitter

Although this library should be installed along with the Twitter Follow Bot if you used pip.

You will also need to create an app account on https://dev.twitter.com/apps

  1. Sign in with your Twitter account
  2. Create a new app account
  3. Modify the settings for that app account to allow read & write
  4. Generate a new OAuth token with those permissions

Following these steps will create 4 tokens that you will need to place in the configuration file discussed below.

Usage

Configuring the bot

Before running the bot, you must first set it up so it can connect to the Twitter API. Create a config.txt file and fill in the following information:

OAUTH_TOKEN:
OAUTH_SECRET:
CONSUMER_KEY:
CONSUMER_SECRET:
TWITTER_HANDLE:
ALREADY_FOLLOWED_FILE:already-followed.txt
FOLLOWERS_FILE:followers.txt
FOLLOWS_FILE:following.txt
USERS_KEEP_FOLLOWING:
USERS_KEEP_UNMUTED:
USERS_KEEP_MUTED:
FOLLOW_BACKOFF_MIN_SECONDS:10
FOLLOW_BACKOFF_MAX_SECONDS:60

OAUTH_TOKEN, OAUTH_SECRET, CONSUMER_KEY, CONSUMER_SECRET are your API keys that you received from creating your app account. TWITTER_HANDLE is your Twitter name, case-sensitive.

You can change the FILE entries if you want to store that information in a specific location on your computer. By default, the files will be created in your current directory.

Add comma-separated Twitter user IDs to the USERS_KEEP entries to:

  • USERS_KEEP_FOLLOWING: Keep following these users even if they don't follow you back.

  • USERS_KEEP_UNMUTED: Keep these users unmuted (i.e., you receive a mobile notification when they tweet)

  • USERS_KEEP_MUTED: Keep these users muted (i.e., you don't receive a mobile notification when they tweet)

For example:

...
FOLLOWS_FILE:following.txt
USERS_KEEP_FOLLOWING:1234,1235,1236
USERS_KEEP_UNMUTED:
...

You can look up a users' Twitter ID here.

Create an instance of the bot

To create an instance of the bot:

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()

By default, the bot will look for a configuration file called config.txt in your current directory.

If you want to use a different configuration file, pass the configuration file to the bot as follows:

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot("my-other-bot-config.txt")

Note that this allows you to run multiple instances of the bot with different configurations, for example if you run multiple Twitter accounts:

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_other_bot = TwitterBot("my-other-bot-config.txt")

Syncing your Twitter following locally

Due to Twitter API rate limiting, the bot must maintain a local cache of all of your followers so it doesn't use all of your API time looking up your followers. It is highly recommended to sync the bot's local cache daily:

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.sync_follows()

The bot will create cache files where you specified in the configuration file.

DO NOT delete the cache files ("followers.txt", "follows.txt", and "already-followed.txt" by default) unless you want to start the bot over with a fresh cache.

Automating Twitter actions with the bot

This bot has several functions for programmatically interacting with Twitter:

Automatically follow any users that tweet something with a specific phrase

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_follow("phrase")

You can also search based on hashtags:

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_follow("#hashtag")

By default, the bot looks up the 100 most recent tweets. You can change this number with the count parameter:

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_follow("phrase", count=1000)

Automatically follow any users that have followed you

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_follow_followers()

Automatically follow any users that follow a user

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot() 
my_bot.auto_follow_followers_of_user("jack", count=1000)

Automatically favorite any tweets that have a specific phrase

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_fav("phrase", count=1000)

Automatically retweet any tweets that have a specific phrase

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_rt("phrase", count=1000)

Automatically unfollow any users that have not followed you back

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_unfollow_nonfollowers()

If there are certain users that you would like to not unfollow, add their user id to the USERS_KEEP_FOLLOWING list.

You will need to manually edit the code if you want to add special users that you will keep following even if they don't follow you back.

Automatically unfollow all users.

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_unfollow_all_followers()

Automatically mute all users that you have followed

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_mute_following()

You will need to manually edit the code if you want to add special users that you will not mute.

Automatically unmute everyone you have muted

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_unmute()

You will need to manually edit the code if you want to add special users that will remain muted.

Post a tweet on twitter

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.send_tweet("Hello world!")

Automatically add users tweeting about something to one of your list

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.auto_add_to_list("#TwitterBot", "twitterbot-list", count=10)

In the example above, the bot will try to add 10 users to the twitterbot-list that are tweeting #TwitterBot.

Remember that the max number of users in a list is 5000.

Have questions? Need help with the bot?

If you're having issues with or have questions about the bot, file an issue in this repository so one of the project managers can get back to you. Please check the existing (and closed) issues to make sure your issue hasn't already been addressed.

twitterfollowbot's People

Contributors

ecolell avatar gitter-badger avatar kennethjmyers avatar kyranb avatar lincete avatar mgoodfellow avatar phocks avatar pkayfire avatar randomarray avatar rhiever avatar teopost avatar umpox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

twitterfollowbot's Issues

auto_follow() is enabling "mobile notifications" also when following

This may be an issue with the python Twitter API but when auto-following using this script it enables "mobile notifications" also meaning that every time a followed user tweets something I get a notification via the mobile app on my phone. Also, if I had SMS activated I would get SMS messages each time those users tweeted, which would be a lot of messages sometimes.

I can manually go and disable mobile notifications, but that would take ages.

Is there any way to modify the script so it follows users but doesn't activate mobile notifications for those users?

screenshot-2014-12-26-14 05

Multiple accounts autofollow and unfollow.

Hi, could someone show me a file they are using for multiple accounts to autofollow and unfollow aswell as auto retweet certain user and favourite a phase. I am really confused on how to this.

Thanks :D im a noob btw

Bot not running

Hi, whenever I try to run the bot I get the following error:

Traceback (most recent call last):
  File "my_bot.py", line 1, in <module>
    from TwitterFollowBot import TwitterBot
  File "/home/TwitterFollowBot-master/TwitterFollowBot/__init__.py", line 99
    "before continuing.", file=sys.stderr)
                              ^
SyntaxError: invalid syntax

Any idea why this is happening?

Move exception lists into config files

Currently, exception lists (e.g., "keep following these users") are hard-coded into the bot. Need to move these exception lists into individual config files.

change to Twitter module?

I have installed the twitter module, but I am receiving this error:

Traceback (most recent call last):
File "/Users/***/twitterbot/twitter_follow_bot.py", line 19, in
from twitter import Twitter, OAuth, TwitterHTTPError
ImportError: cannot import name Twitter

I am running python 2.7

Here is my confirmation that the twitter module is installed through easy_install:

"Adding twitter 1.10.2 to easy-install.pth file
Installing twitter-log script to /usr/local/bin
Installing twitter script to /usr/local/bin
Installing twitterbot script to /usr/local/bin
Installing twitter-follow script to /usr/local/bin
Installing twitter-stream-example script to /usr/local/bin
Installing twitter-archiver script to /usr/local/bin

Getting A no module name twitter error

this is what I'm getting

Traceback (most recent call last):
File "/Users/jeremyyoung/Desktop/TwitterFollowBot-master/TwitterFollowBot/init.py", line 21, in
from twitter import Twitter, OAuth, TwitterHTTPError
ImportError: No module named 'twitter

Any Help?

Support for multiple twitter accounts

I'm thinking about adding support for multiple twitter accounts. Would first probably start by detaching the configuration in twitter_follow_bot #L25-29. Thoughts all?

Stacking actions

I have been trying to understand the psychology of why people follow random accounts on twitter. I am interested in seeing if people are more willing to follow people back if there are multiple actions instead of one. It is pretty common to get a favorite on status that includes SEO or whatever keyword. So what I am interested in doing is have the bot follow people based on who they follow, but after they follow them it favorites a random tweet range [0...20] or multiple tweets. I have done this with instagram and I got pretty good results. In the future it would be cool to log results and calculate conversion based on main account scraped from, but thats another time.

So what I am wondering is what variable do I use to favorite a tweet of the user I just followed? I only see the user id.

Keep getting rate limited

Hello!

I've been playing with TwitterFollowBot to favorite Tweets, but keep having issues getting rate limited.

Am I using it properly? Here's the code I'm using:

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()

while True:
my_bot.auto_fav("#FalloutShelter", count=100)
wait(3600)

Already-followed.csv not getting written

Heya,

Just a quick one I can't see to get this to write out to the CSV file, the CSV filename I specified was "./already-followed.csv"

Any ideas?

Cheers

Marc

Some suggestions that may be interesting.

Hello!, I am really new coding python but I got some ideas you may like.

I Saw that
auto_unfollow_nonfollowers(): deletes all the nonfollowers but if you do auto_follow often maybe you follow so much people that wouldnt follow you back and its so agressive, so I figured a way to prevent that only changing the definition and one line.def auto_unfollow_nonfollowers(self,count=None):
and just before the file writings and unfollowing not_following_back = not_following_back[:count]
So if you dont set the count the bot will work normal and if you set it will go only on the interval, so you dont hit rate limits.

No such file or directory: 'config.txt'

How do I fix this error? I have the config.txt file in the TwitterFollowBot folder within this directory anaconda>lib>site>site-packages>TwitterFollowBot.

I have already appended this directory into python.

I'm just following the code

from TwitterFollowBot import TwitterBot
my_bot = TwitterBot()

sync_follows() problem

Hey buddy! I get this error message:

Traceback (most recent call last):
File "twitterbot.py", line 10, in
my_bot.sync_follows()
File "/usr/local/lib/python2.7/dist-packages/TwitterFollowBot/init.py", line 122, in sync_follows
followers_status = self.TWITTER_CONNECTION.followers.ids(screen_name=self.BOT_CONFIG["TWITTER_HANDLE"])
File "/usr/local/lib/python2.7/dist-packages/twitter/api.py", line 308, in call
return self._handle_response(req, uri, arg_data, _timeout)
File "/usr/local/lib/python2.7/dist-packages/twitter/api.py", line 341, in _handle_response
raise TwitterHTTPError(e, uri, self.format, arg_data)
twitter.api.TwitterHTTPError: Twitter sent status 404 for URL: 1.1/followers/ids.json using parameters: (oauth_consumer_key=

and then it shows my datas.

I also noticed that I can't force follow users by adding their twitter IDs' in the config file.

What i did:

uninstalled and installed again "twitter" and "TwitterFollowBot".

Hope you have some idea. :)

DM a User ?

Is there a method to DM an User who is following us ? Thanks for the amazing Work.

Module names should not contain dash

It's wrong to call a file twitter-follow-bot.py - In python you should always name files with underscore instead of dash. So it would be correct to call it twitter_follow_bot.py because then it's actually possible to import the file.

Gain speed

Hello everyone, I just tested the bot and I find them very interesting possibility. I think there is much to do but I find execution is very long! You find things to make it faster?

Creating an instance

When creating an instance of the bot I get this error: IndexError: list index out of range, any help?

blacklist user(s)

Hello,

It could be helpful to be able to provide a list of blacklisted users.
The idea is that the bot should never follow the users on that list, no matter what.

It happens that I manually unfollow spammers (or accounts that no longer post anything) and sometimes they get auto-followed again (for example, because some other user still follows them and when i call auto_follow_followers_of_user they get followed again).

This could be made adding another .txt file where the IDs can be listed.

Kind Regards,

Francisco

Syntax error in the first example in docs.

The first example goes :
Examples::

    t = Twitter(
        auth=OAuth(token, token_key, con_secret, con_secret_key)))

it should be Examples::

    t = Twitter(
        auth=OAuth(token, token_key, con_secret, con_secret_key))

Location

Hey I was looking through the api and saw that there is support for geolocation. Any plans to add this search? Its also possible to add location via the q parameter.

auto_unfollow_nonfollowers() error

Choosing time between 10 and 60 - waiting 31 seconds before action
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\twitter\api.py", line 315, in _handle_response
handle = urllib_request.urlopen(req, *_kwargs)
File "C:\Python34\lib\urllib\request.py", line 161, in urlopen
return opener.open(url, data, timeout)
File "C:\Python34\lib\urllib\request.py", line 469, in open
response = meth(req, response)
File "C:\Python34\lib\urllib\request.py", line 579, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python34\lib\urllib\request.py", line 507, in error
return self._call_chain(_args)
File "C:\Python34\lib\urllib\request.py", line 441, in _call_chain
result = func(*args)
File "C:\Python34\lib\urllib\request.py", line 587, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "start_bot_unfollow.py", line 4, in
my_bot.auto_unfollow_nonfollowers()
File "C:\Python34\twitterfollowbot\TwitterFollowBot__init__.py", line 426, in auto_unfollow_nonfollowers
self.TWITTER_CONNECTION.friendships.destroy(user_id=user_id)
File "C:\Python34\lib\site-packages\twitter\api.py", line 308, in call
return self._handle_response(req, uri, arg_data, _timeout)
File "C:\Python34\lib\site-packages\twitter\api.py", line 341, in _handle_response
raise TwitterHTTPError(e, uri, self.format, arg_data)
twitter.api.TwitterHTTPError: Twitter sent status 403 for URL: 1.1/friendships/destroy.json using parameters: (oauth_consumer_key=TPG0beLUoVv5C71nWWnfJCkg3&oaut
h_nonce=10443273249529987898&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1437903876&oauth_token=3371608815-Fg5J2wc4mHkus8RwVWE9XLmf92PmU9IkPF25P7V&oauth_ve
rsion=1.0&user_id=1427030012&oauth_signature=XmL3f49B4DkOKLPYncqg2JYbS34%3D)
details: {'errors': [{'code': 261, 'message': 'Application cannot perform write actions. Contact Twitter Platform Operations through https://support.twitter.com
/forms/platform'}]}

Line 426 in init.py is
self.TWITTER_CONNECTION.friendships.destroy(user_id=user_id)

Setting up the Bot

Hello can you please give me a more detailed way to setup this bot please?

Thanks

ImportError: cannot import name TwitterBot

Traceback (most recent call last):
File "twitter.py", line 8, in
from TwitterFollowBot import TwitterBot
File "/usr/local/lib/python2.7/dist-packages/TwitterFollowBot/init.py", line 21, in
from twitter import Twitter, OAuth, TwitterHTTPError
File "/home/ubuntu/twitter.py", line 8, in
from TwitterFollowBot import TwitterBot
ImportError: cannot import name TwitterBot

I am on an ubuntu 14.04 box, I've installed pip, TwitterFollowBot, Twitter, birdy, requests, and I get this error only on my Ubuntu 14.04 server. The script runs fine on my main PC Xubuntu 15

Licensing

The licensing of this module may prevent MIT/BSD licensed modules from being used to make improvements. GPL doesn't play nicely with them. May I suggest something a bit more permissive, such as MIT?

Offset to auto_follow_followers_of_user?

Currently if i get like 5 users, it gets same people every time until someone else will follow. Is there a way to get 500 users with 500 offset?

Also, what is the limit of this request?

Suggestions

Just suggestions….

I'm using path.dirname for config.txt path. It works well with linux distros like OpenShift:

script_path = os.path.dirname(os.path.abspath( __file__ ))
config_file= script_path + "/config.txt")

Idea: I'm using blacklist.txt for retweets. It's same as get_do_not_follow_list. Useful if you dont want to retweet from someone.

BLACKLIST_FILE = script_path + '/blacklist.txt'

def get_do_not_retweet_list(self):
        """
           Returns list of users the bot dont retweet.
        """
        if not os.path.isfile(BLACKLIST_FILE):
            with open(BLACKLIST_FILE, "r") as out_file:
                out_file.write("")


        do_not_retweet = set()
        dnr_list = []
        with open(BLACKLIST_FILE) as in_file:
            for line in in_file:
                dnr_list.append(int(line))


        do_not_retweet.update(set(dnr_list))
        del dnr_list

        return do_not_retweet

Idea: don't try to retweet already tweeted. Looks like trying to retweet same tweet(searching same hash) many times cause a problem(spam and rate limit). I am going to try to record all retweeted tweet ID's as txt file. If the Tweet ID match do not to try to retweet.

Improving Rate Limit: Rate Limit returns how long you shoud wait as time format. This is complex i know. Just an idea… Don't break the script, wait until limit and continue….

Unfollow Limit

Is there a way to set a limit on how many people you Unfollow? because I just had my app banned due to mass unfollow! I'd like to keep it at around 700

Retweet: Number of Hashtags & Number of Mentions

Hi,

I'm currently trying to see if we could add conditions to the retweet bot to enhance quality of retweets.

If we wanted to limit the number of hashtags in the tweet before retweeting and the number of mentions, how would you go about it?

Thanks for your help!!
LX

Followback Error

Hello all, its me again! I have found I get this error when I use the "followback" part of the script.

error: Twitter sent status 403 for URL: 1.1/friendships/create.json using parameters: (follow=True&oauth_consumer_key=oYxgv1tcSytGltLLVbt8o8e00&oauth_nonce=12856182260854981849&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1421159406&oauth_token=174290919-cXlnGvIORpkxhnfXYX7jPPCnyTy6u71GWeYtmMa0&oauth_version=1.0&user_id=174284407&oauth_signature=bjLoXdNHAlnBqnBVC%2FjCmvzGcKY%3D)
details: {"errors":[{"code":160,"message":"You've already requested to follow jajayannie."}]}

I can see the problem but unsure how we can bypass people already requested, because at some point this followback script will hit a dead end if people don't accept the requests.

Remove invalid IDs from following list

It might sound a little bit weird, but the unfollow function wasn't working for me anymore (raised errors). I am wrote out the user IDs upon which the API crashed, and I identified ~10 IDs in my following list that caused this problem.

If I ignore those IDs, everything works fine and I can unfollow people again (If I try to unfollow those IDs, the API raises errors and crashes). However, what is weird about those IDs is that they don't correspond to valid twitter handles.

I am wondering how I could remove them from my "following" list.

An example for such an invalid user id: 2455461907

Any ideas?

Adding timing

Anyway of adding timing such as at 10AM unfollow everyone etc?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.