From cdc28cb3f3d1db681d0eb7112eb67f6595227b8c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20T=C3=A9tard?= Date: Sat, 14 Nov 2015 10:58:26 +0100 Subject: [PATCH] =?utf8?q?N=E2=80=99afficher=20que=20les=20fichiers=20d?= =?utf8?q?=C3=A9j=C3=A0=20trait=C3=A9s=20sur=20la=20home?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- femtoblackweb.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/femtoblackweb.py b/femtoblackweb.py index aafd48d..aab1433 100644 --- a/femtoblackweb.py +++ b/femtoblackweb.py @@ -26,6 +26,7 @@ app.config.update({ 'MAX_CONTENT_LENGTH': 50 * 1024 * 1024, 'BOOTSTRAP_SERVE_LOCAL': True, 'BOOTSTRAP_QUERYSTRING_REVVING': True, + 'ALLOWED_EXTENSIONS' : ['mp3', 'ogg'], }) app.config.from_envvar('FEMTOBLACK_SETTINGS', silent=True) @@ -38,15 +39,26 @@ def page_not_found(e): @app.route('/') def index(): - files = [p.name for p in pathlib.Path(app.config['UPLOAD_FOLDER']).iterdir() if p.is_file()] + """Affiche la liste des fichiers `.ogg` pour lesquel nous avons un + fichier `.json` a côté (fichier d’analyse). + + """ + files = [] + + for p in pathlib.Path(app.config['UPLOAD_FOLDER']).iterdir(): + (filename, ext) = os.path.splitext(p.name) + json_file = os.path.join(app.config['UPLOAD_FOLDER'], "{}.json".format(p.name)) + + if p.is_file() and ext[1:] in app.config['ALLOWED_EXTENSIONS'] and os.path.exists(json_file): + files.append(p.name) + return render_template('index.html', files=files) @app.route('/upload', methods=['GET', 'POST']) def upload_file(): def allowed_file(filename): - ALLOWED_EXTENSIONS = ['mp3', 'ogg'] - return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS + return '.' in filename and filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS'] if request.method == 'POST': f = request.files['file'] -- 2.30.2