It occurred to me that I could enter this challenge in a completely straight-forward manner: by writing a traditional comedy set. This idea was immediately displaced by the urge to do something techie, so I started writing a script that could pull down humorous material from the web. Reddit seemed like a good place to look, given that it has a metric crapload of commentary to draw from (the following assumes you’re working in OSX).
- Make a new reddit account
- Follow these steps to create a script-type application (just follow the “first steps” section).
- Open your terminal and easy_install pip (may need sudo)
- Now create a virtual Python environment for your project and activate it. Do this so random updates don’t tank your script. Take special note of source venv/bin/activate , which will put you in virtual mode for the next steps.
- pip install praw
- python mybot.py
- This script looks for comments that include the words “tragedy” or “time” and prints them in the terminal.
- For the final output I installed Soundflower, which allowed me to record straight off the sound card. I then had the OSX accessibility assistants read the text aloud and laugh at it robotically.
- See python code below:
QUESTIONS = ['tragedy', 'time']
x = True
# you'll need to get the stuff below yourself before this script will work
reddit = praw.Reddit(user_agent='YOUR_USER_AGENT',
for comment in reddit.subreddit('all').stream.comments():
if x == True:
question_phrase = ' time '
if x == False:
question_phrase = 'trump'
if question_phrase in comment.body:
x = not x