Created
September 19, 2022 13:56
-
-
Save ipmb/de82d95a06f04eefa7e32deccf4cac46 to your computer and use it in GitHub Desktop.
This file contains 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
import json | |
import random | |
import http.client | |
# make call to cat facts API | |
# https://cat-fact.herokuapp.com/facts | |
conn = http.client.HTTPSConnection("cat-fact.herokuapp.com") | |
conn.request("GET", "/facts") | |
response = conn.getresponse() | |
# extract data from response | |
# it is a list of dictionaries | |
# with a key named "text" containing the fact | |
data = json.load(response) | |
fact = random.choice(data) | |
print(fact["text"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment