-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdadjoke2022-PROJECT.py
34 lines (29 loc) · 988 Bytes
/
dadjoke2022-PROJECT.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pyfiglet
import termcolor
import requests
from random import choice
# Testing
inp2 = input("Do you want to have a dad jokes? [yes/no] ")
website = "https://icanhazdadjoke.com/search"
opening = pyfiglet.figlet_format("DADJOKE2022")
coloropening = termcolor.colored(opening, "red")
print(coloropening)
while inp2 == "yes":
try:
inp1 = input("Let me tell you a joke. Give me a topic: ")
req = requests.get(
website, headers={"Accept": "application/json"}, params={"term": inp1}
).json()
result = req["results"]
print(
f"I've got "
+ str(len(req["results"]))
+ " jokes about "
+ inp1
+ ". Here's one: "
)
print(choice(result)["joke"])
inp2 = input("Do you want to try again? ")
except IndexError:
print("Sorry, there's no dad jokes for that")
inp2 = input("Do you want to try again? ")