Home

Awesome

twitterImgBot

There are way too many pretty pictures in the world to tweet all of them. twitterImgBot tries to solve just that.

The primary objective of this script is to tweet a random picture from a given folder. But it does some other things too and has some pretty nice things built in as well. See the features.

It can easily be used together with cron or another task scheduler to create a twitter bot. All you need is a computer with internet connection, python, tweepy and folder with a bunch of images.

Features

Setup

You need:

You'll probably also want a task scheduler like cron to fully automate the bot.

Python3 comes with pretty much every modern distro, but you probably don't have tweepy installed. You should install pip.

sudo apt-get install python3-pip

and then tweepy

pip install tweepy

You should then complete the settings file inside the settings folder. There's a detailed explanation of every setting and also an example config file in the Options section. Please:

The bot WILL probably fail if these conditions are not met.

Options

Explanation

Example

# Replace where appropriate with your own settings.

[Twitter]
api_key = your_api_key
secret_key = your_secret_key
token = your_token
secret_token = your_secret_token

[App]
image_folder = /home/botImages/
execution_chance = 1
allow_repeat_after = 50
log_file = /home/bot/logs/log
bot_account = @gentelindaOK
master_account = @amemulo
dont_tweet_file = /home/bot/logs/banned

[Orders]
#caps agnostic
ban_command = @gentelindaOK don't
request_command = dear @gentelindaOK
time_tolerance = 5

[Texts]
# Respect indentation: it is TWO spaces
# tweet_post_number is either True or False, nothing else
# tweet this text doesn't requiere "" or '', just write the text
tweet_post_number = True
tweet_this_text = 
request_answers = specially for you. xoxo
  only because you asked nicely. xoxo
  this is one of my best. be grateful. xoxo
  when you see your human partner, think of me. xoxo
  remember: if you like it put a password on it. xoxo
  humans are warmer. but what if you like the cold?. xoxo
  can you feel your species deprecation?. xoxo
request_to_third_answers = you just got a nice gift from
  apparently this person likes you

Backwards Compatibilty

Please note that if you were using a previous version of the bot you'll have to execute the bot once (and only once!) like this from the terminal after enabling the option. This is specially important if you want to use the tweet_post_number option.

python twitterbot.py --tweet --tweetnumber X

Where X is the number of the tweet you'll post right now (that is, the number of posts the bot has tweeted plus one, you can see the number so far on tweeter).

This will log that tweet in a way so that the bot can read the post number from the log, so it will know now how many posts there have been. The --tweet option is there just to force the bot to tweet and ignore the execution chance.

If you don't do this, your log will register the bot's post_number wrongly, starting from one since you updated. Of course, if you use the tweet_post_number function, this'll mean the post numbers the bot tweetes will make no sense.

Usage

Execute it. That's it.

You also have a couple of useful arguments:

optional arguments:
  -h, --help  show this help message and exit
  --tweet     Ignores execution chance, always run
  --test      Wont't tweet, just write to log
  --postnumber Sets the post number to be posted if tweet_post_number is true. 

Live example and full automation idea

You can check out gentelindaOK (NSFW) to see a working account using this twitter bot.

@gentelindaOK is a fully automatic bot. My modified version of RedditImageGrab downloads new images to my PC from a multireddit every morning. Then, a silly one line bash command removes any image that is smaller than 50kb (to filter glitches and very small pictures). This twitter bot is set up on cron on my PC to execute every minute with a 1 percent execution chance set on the script's config file.