Skip to content

Instantly share code, notes, and snippets.

@OdinsHat
Created March 26, 2014 13:22
Show Gist options
  • Save OdinsHat/9783014 to your computer and use it in GitHub Desktop.
Save OdinsHat/9783014 to your computer and use it in GitHub Desktop.
Random Reddit joke from top 20 at r/jokes
import praw
from random import choice
def joke():
"""Prints a joke from a random selection of the
top 20 reddit jokes in r/jokes
"""
r = praw.Reddit(user_agent="Reddit Joke Grabber")
subs = r.get_subreddit("jokes").get_hot(limit=20)
jokes = list(subs)
thejoke = choice(jokes)
print("%s\n%s" % (thejoke.title, thejoke.selftext))
if __name__ == "__main__":
joke()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment