Skip to content

Instantly share code, notes, and snippets.

@ipmb
Created September 19, 2022 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipmb/de82d95a06f04eefa7e32deccf4cac46 to your computer and use it in GitHub Desktop.
Save ipmb/de82d95a06f04eefa7e32deccf4cac46 to your computer and use it in GitHub Desktop.
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