Meghan Trainor (no not that one) pitched us a curveball in Episode 3 with the “stand up comedy” challenge. Nick Bontranger was up to the task, and you can listen to his response here.
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'] import praw import time x = True # you'll need to get the stuff below yourself before this script will work # https://github.com/reddit/reddit/wiki/OAuth2-Quick-Start-Example#first-steps reddit = praw.Reddit(user_agent='YOUR_USER_AGENT', client_id='YOUR_CLIENT_ID', client_secret="YOUR_SECRET") 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: print(comment.body) print("---") x = not x