import codecs with codecs.open("build.py", "r", "utf-8") as f: lines = f.readlines() new_topics = [] new_topics.append(' {"slug": "school", "name": "Dad Jokes About School", "emoji": "\\U0001F392",\n') new_topics.append(' "intro": "Class clown certified jokes for teachers, students, and anyone who survived homework. These school dad jokes will get you a passing grade in groans.",\n') new_topics.append(' "keywords": r"\\b(school|teacher|class|student|homework|math|book|read|study)\\b"},\n') new_topics.append(' {"slug": "cars", "name": "Dad Jokes About Cars", "emoji": "\\U0001F697",\n') new_topics.append(' "intro": "Drive everyone up the wall during your next road trip. These car dad jokes are strictly automatic when it comes to terrible punchlines.",\n') new_topics.append(' "keywords": r"\\b(car|drive|road|truck|tire|wheel|traffic)\\b"},\n') new_topics.append(' {"slug": "ocean", "name": "Dad Jokes About the Ocean", "emoji": "\\U0001F30A",\n') new_topics.append(' "intro": "Water you waiting for? Dive into these shore-fire maritime puns. These ocean dad jokes will make waves at any beach party.",\n') new_topics.append(' "keywords": r"\\b(ocean|sea|beach|water|tides?|waves?|boat|ship|sail|sand|sharks?|fish)\\b"},\n') out = [] for i, line in enumerate(lines): if line.strip() == ']': # Check if we are closing TOPICS = [ # It's at line 46 normally. if i < 70 and not any('school' in L for L in out[-5:]): out.extend(new_topics) out.append(line) with codecs.open("build.py", "w", "utf-8") as f: f.writelines(out)