Last active
November 29, 2018 20:00
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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