Twitterbot Skeleton

Continuing on with the Twitter Bot Memo assignment, now try to write some boilerplate documentation/pseudocode that you think your bot needs.


In your compjour-hw repo, reuse the folder named twitterbot. Then place files as needed into that directory:

|--- comjour-hw/
    |------- twitterbot/

Things to do

Get registered with Twitter

By now, you should have done the steps in: Getting Started with Tweepy, including having a Twitter app registered.

And you should also have a "bot" account, not your true twitter account, but one that you can send tweets through. The next step is to register that bot account as a user of that Twitter app you just created (you will need to be able to operate two browsers at once):

Twitter App Authentication Process

By the end of it, you should have some kind of credentials file somewhere on your file system. DO NOT put it in your compjour-hw repo, or else it will be pushed onto the Github server! Save it somewhere like:


Test out my Tweepy wrapper methods

Check out the code (and memo) for my simple Yolobro Twitter bot.

Take particular look at the script.

Copy the code there and make a in your compjour-hw/twitterbot folder.

Then try this from your terminal:

# assuming your folder is somewhere on your Desktop
cd ~/Desktop/compjour-hw/twitterbot

Now inside iPython:

import twit_utils
# assuming you have a creds file named "~/Desktop/tw.json"
CREDS_FILE = "~/Desktop/tw.json"
api = twit_utils.get_api(CREDS_FILE)
obj =
print("My name is", obj.screen_name)

Write your own and

Inside the compjour-hw/twitterbot/ folder, create:


Look again at my yolobro example.

In, define functions that pertain to the steps that you think you'll run. You don't have to write any real code, but you do have to include a docstring comment that explains, briefly:

  1. What the function does
  2. What arguments it takes, and what the types of those arguments are
  3. What the function returns

Some examples:

def make_yolobro_text():
    Create a custom #YOLOBRO happy message
        A text string with the #YOLOBRO hashtag and something extra special
    if random() > 0.7:
        return "#YOLOBRO YOU MY BRO!"
        return "#YOLOBRO YO YO"

def latest_yolobro_reply(tweets):
    Given a list of tweets (ostensibly from user_timeline API endpoint),
    find the earliest one that has the #YOLOBRO hashtag in it

        tweets (list): a list of Twitter tweet objects that are dicts

        if any such tweet is found, return that tweet (dict)
        else, return None
    for tweet in tweets:
        tags = [tag for tag in tweet['entities']['hashtags'] if tag['text'].upper() == 'YOLOBRO']
        if len(tags) > 0:
            return tweet

In this should contain a single function, make_it_so(), and any other dependencies (such as importing and The steps you plan to take will run in the body of that make_it_so() function

The file is meant for your usage, so that you don't have to become a master of the Twitter API to just send out a tweet, or search for things.