Skip to content

Instantly share code, notes, and snippets.

@AO8
Last active November 29, 2018 20:00
Show Gist options
  • Select an option

  • Save AO8/74a3a81fd672a6f8d0cc149ed62295de to your computer and use it in GitHub Desktop.

Select an option

Save AO8/74a3a81fd672a6f8d0cc149ed62295de to your computer and use it in GitHub Desktop.
Fetch a random joke from the Internet Chuck Norris Database (ICNDb) with Python 3 and Requests.
# Learn more about the ICNDb API at: http://www.icndb.com/api/
# Learn more about the Requests library at: http://docs.python-requests.org/en/master/
import requests
def get_joke():
"""fetches and prints a random joke"""
url = "http://api.icndb.com/jokes/random"
resp = requests.get(url)
resp.encoding = "utf-8"
data = resp.json()
print(data["value"]["joke"])
get_joke()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment