30 lines
931 B
Python
Executable File
30 lines
931 B
Python
Executable File
#!/usr/bin/python3
|
|
import random, glob, os, json
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
songs_folder = "/songs"
|
|
jingles_folder = "/jingles"
|
|
|
|
if not os.path.isfile(f"{songs_folder}/state.json"):
|
|
# create state file if it doesnt exist
|
|
with open(f"{songs_folder}/state.json", "w") as f:
|
|
state = {"current_song_type": "jingle"}
|
|
json.dump(state, f, indent=4)
|
|
else:
|
|
with open(f"{songs_folder}/state.json") as f:
|
|
state = json.load(f)
|
|
|
|
if state["current_song_type"] == "song":
|
|
state["current_song_type"] = "jingle"
|
|
print(random.choice(glob.glob(f"{jingles_folder}/*.ogg")))
|
|
elif state["current_song_type"] == "jingle":
|
|
state["current_song_type"] = "song"
|
|
print(random.choice(glob.glob(f"{songs_folder}/*.ogg")))
|
|
else:
|
|
exit(1)
|
|
|
|
with open(f"{songs_folder}/state.json", "w") as f:
|
|
json.dump(state, f, indent=4)
|