-
Notifications
You must be signed in to change notification settings - Fork 0
/
personal-accompanist.py
70 lines (45 loc) · 1.5 KB
/
personal-accompanist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import time
import streamlit as st
from p_a import PersonalAccompanist
def init_session() -> PersonalAccompanist:
st.set_page_config(layout="wide")
for folder in ['./.lilypond', './.assets']:
if not os.path.exists(folder):
os.mkdir(folder)
st.session_state.p_a = PersonalAccompanist()
return st.session_state.p_a
def clean_up() -> None:
"""
remove old files
"""
# delete everything that is older than 600 seconds in the `./.tmp` folder
# and older the two hours in the `./.assets` folder
for folder, age in [('./.lilypond', 600), ('./.assets', 7200)]:
content = os.listdir(folder)
# print(content)
for entry in content:
file = f'{folder}/{entry}'
file_time = os.path.getmtime(file)
if (time.time() - file_time) > age:
os.remove(file)
def main():
rerun = False
if "p_a" not in st.session_state:
# ok, then this is the initial run
# Prepare the app session with class instances and variables.
# We keep our stuff in an own class instance to avoid name space conflicts
# this instance is stored in `st.sessionstate.p_a`
p_a = init_session()
rerun = True
else:
p_a = st.session_state.p_a
p_a.exercises.update_variables()
p_a.lilypond.prepare()
p_a.audio.prepare()
p_a.gui.show_gui()
clean_up()
if rerun:
st.rerun()
if __name__ == "__main__":
main()