diff --git a/.sampleplayer.py.swp b/.sampleplayer.py.swp new file mode 100644 index 0000000..7a363bf Binary files /dev/null and b/.sampleplayer.py.swp differ diff --git a/__pycache__/sampleplayer.cpython-310.pyc b/__pycache__/sampleplayer.cpython-310.pyc index f500f8b..17f429b 100644 Binary files a/__pycache__/sampleplayer.cpython-310.pyc and b/__pycache__/sampleplayer.cpython-310.pyc differ diff --git a/sampleplayer.py b/sampleplayer.py index 5eb19c4..ae26827 100644 --- a/sampleplayer.py +++ b/sampleplayer.py @@ -1,9 +1,26 @@ +from playsound import playsound from flask import Flask - +from flask import render_template +from markupsafe import escape +from os import listdir +from os.path import join app = Flask(__name__) +samplefiles = listdir('samples') +samples = [] +for f in samplefiles: + if '.wav' in f: + samples.append(f.replace('.wav', '')) @app.route('/') def hello(): - return '

Hello, World!

' + return render_template('index.html', samples=samples) + +@app.route('/play/') +def door(sample): + if sample in samples: + playsound(join('samples', f'{sample}.wav')) + return f'

{escape(sample)}!

' + else: + return 'no such sample' diff --git a/samples/door.wav b/samples/door.wav new file mode 100644 index 0000000..2f762b4 Binary files /dev/null and b/samples/door.wav differ diff --git a/templates/.index.html.swp b/templates/.index.html.swp new file mode 100644 index 0000000..de5abeb Binary files /dev/null and b/templates/.index.html.swp differ diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..eaddc3c --- /dev/null +++ b/templates/index.html @@ -0,0 +1,48 @@ + + + +Sample Player + + + + + + + + +
+

Sample Player

+

This domain is for use in illustrative examples in documents. You may use this +domain in literature without prior coordination or asking for permission.

+{% for sample in samples %} +

{{sample}}

+{% endfor %} +
+ +