Record#
- Continue studying the points of request and json today.
- Use the
headers={"Accept":"application/json"}
parameter to specify the format of the returned content. - Today's exercise is to get and display a joke from
[icanhazdadjoke](https://icanhazdadjoke.com/)
, and ask the user if they want to save or perform the next operation.
CODE#
main.py#
import requests, json
from replit import db
while True:
result = requests.get("https://icanhazdadjoke.com/",
headers={"Accept": "application/json"})
joke = result.json()
id = joke["id"]
text = joke["joke"]
print(text)
print()
menu = input("(s)ave joke, (l)oad old jokes, (n)ew joke\n")
if menu == "s":
db[id] = {"joke": text}
elif menu == "l":
for key in db.keys():
print(db[key]["joke"])
print()