Created
August 15, 2022 15:11
-
-
Save Mark-McCracken/6b35367780cbbd324bcb9d7b7f4ddc14 to your computer and use it in GitHub Desktop.
create_music_round.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_music_round(): | |
prs.slides.add_slide(slide_layouts.get_by_name("MUSIC_ROUND_INTRO")) | |
def create_song_obj_from_folder(folder): | |
try: | |
question = next(file_path for file_path in listdir(path.join("questions", "songs", folder)) if re.match("^question\.(mp3|m4a)$", file_path)) | |
answer = question | |
try: | |
answer = next(file_path for file_path in listdir(path.join("questions", "songs", folder)) if re.match("^answer\.(mp3|m4a)$", file_path)) | |
except: | |
pass | |
img_1 = next(file_path for file_path in listdir(path.join("questions", "songs", folder)) if re.match("^img_1\.(jpe?g|png)$", file_path)) | |
img_2 = next(file_path for file_path in listdir(path.join("questions", "songs", folder)) if re.match("^img_2\.(jpe?g|png)$", file_path)) | |
return {"question_track": question, "answer_track": answer, "folder": folder, "img_1": img_1, "img_2": img_2} | |
except: | |
print(f"Error encountered trying to find right files in folder {folder}") | |
exit(1) | |
songs = [create_song_obj_from_folder(f) for f in listdir(path.join("questions", "songs")) if not re.match(".DS_Store", f)] | |
assert len(songs) == 10, "Need to have 10 folders for audio files in the questions/songs folder" | |
for idx, song in enumerate(songs): | |
music_question_slide = prs.slides.add_slide(slide_layouts.get_by_name("MUSIC_ROUND_QUESTION")) | |
music_question_slide.shapes.add_movie( | |
path.join("questions", "songs", song["folder"], song["question_track"]), | |
left=Cm(20), top=Cm(-5), width=Cm(2), height=Cm(2), | |
mime_type='audio/mp3') | |
music_question_slide.placeholders[22].text = f"Track {idx+1}" | |
prs.slides.add_slide(slide_layouts.get_by_name("MUSIC_ROUND_ANSWER_BREAK")) | |
for idx, song in enumerate(songs): | |
music_answer_slide = prs.slides.add_slide(slide_layouts.get_by_name("MUSIC_ROUND_ANSWER")) | |
music_answer_slide.shapes.add_movie( | |
path.join("questions", "songs", song["folder"], song["answer_track"]), | |
left=Cm(20), top=Cm(-5), width=Cm(2), height=Cm(2), | |
mime_type='audio/mp3') | |
music_answer_slide.placeholders[22].text = f"Track {idx+1}" | |
music_answer_slide.placeholders[23].text = song["folder"] | |
music_answer_slide.placeholders[24].insert_picture(path.join("questions", "songs", song["folder"], song["img_1"])) | |
music_answer_slide.placeholders[25].insert_picture(path.join("questions", "songs", song["folder"], song["img_2"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment