37 lines
927 B
Python
Executable File
37 lines
927 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import requests
|
|
import time
|
|
|
|
|
|
def download(url):
|
|
response = requests.get(url)
|
|
return response.json()
|
|
|
|
|
|
def main():
|
|
iterations = 0
|
|
while iterations < 3:
|
|
iterations += 1
|
|
programming_jokes = {}
|
|
while len(programming_jokes) < 5:
|
|
# Parse the JSON response
|
|
jokes = download("https://official-joke-api.appspot.com/jokes/random/10")
|
|
|
|
# Filter to just programming jokes and insert them
|
|
for joke in jokes:
|
|
if joke["type"] == "programming":
|
|
programming_jokes[joke["id"]] = joke
|
|
for joke in programming_jokes.values():
|
|
print(joke["setup"])
|
|
for _ in range(3):
|
|
print(".", end="", flush=True)
|
|
time.sleep(1)
|
|
print()
|
|
print(joke["punchline"])
|
|
time.sleep(2)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|