fixed SLI's bug (<3)
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Aethor 2021-11-25 18:49:58 +01:00
parent ef6ee2e3c6
commit 24367d1b98
1 changed files with 14 additions and 4 deletions

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python3
from json.decoder import JSONDecodeError
import random, glob, os, json
@ -11,15 +12,24 @@ if __name__ == "__main__":
def get_air_support():
return random.choice(glob.glob(f"{air_support_folder}/*.ogg"))
def create_state_from_scratch() -> dict:
state = {"current_song_type": "jingle"}
with open(f"{songs_folder}/state.json", "w") as f:
json.dump(state, f, indent=4)
return state
# state loading
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)
state = create_state_from_scratch()
else:
with open(f"{songs_folder}/state.json") as f:
state = json.load(f)
try:
with open(f"{songs_folder}/state.json") as f:
state = json.load(f)
except JSONDecodeError:
# if file doesnt exist, we recreate a state on the disk
state = create_state_from_scratch()
# song choice
if state["current_song_type"] == "song":