bestdadjokes/update_jokes.py

33 lines
1.5 KiB
Python

import json
import uuid
import sys
new_jokes = [
{"setup": "Why don't ants get sick?", "punch": "Because they have little anty-bodies.", "cat": "animals"},
{"setup": "How do you make a tissue dance?", "punch": "Put a little boogie in it.", "cat": "one-liners"},
{"setup": "Why did the Oreo go to the dentist?", "punch": "Because it lost its filling.", "cat": "food"},
{"setup": "How do you weigh a millennial?", "punch": "In Instagrams.", "cat": "tech"},
{"setup": "What do you call a bear in the rain?", "punch": "A drizzly bear.", "cat": "weather"},
{"setup": "Why are snails so bad at racing?", "punch": "They are sluggish.", "cat": "sports"},
{"setup": "What's an astronaut's favorite board game?", "punch": "Moon-opoly.", "cat": "space"},
{"setup": "Why did the banana go to the hair salon?", "punch": "It had split ends.", "cat": "food"},
{"setup": "How do you track Will Smith in the snow?", "punch": "You follow the fresh prints.", "cat": "weather"},
{"setup": "What do you call a sheep covered in chocolate?", "punch": "A candy baa.", "cat": "food"}
]
try:
with open("content/jokes.json", "r") as f:
data = json.load(f)
for j in new_jokes:
j["id"] = str(uuid.uuid4())
data["jokes"].append(j)
with open("content/jokes.json", "w") as f:
json.dump(data, f, indent=4)
f.write("\n")
print("Successfully added 10 jokes.")
except Exception as e:
print(f"Error: {e}")
sys.exit(1)