Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -439,6 +439,50 @@ def zip_folder(foldername):
|
|
439 |
# Send the zipped file to the client
|
440 |
return send_from_directory(app.config['MAIN_FOLDER'], zip_filename, as_attachment=True)
|
441 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
442 |
if __name__ == '__main__':
|
443 |
app.run(debug=True)
|
444 |
|
|
|
439 |
# Send the zipped file to the client
|
440 |
return send_from_directory(app.config['MAIN_FOLDER'], zip_filename, as_attachment=True)
|
441 |
|
442 |
+
@app.route('/upload_data_file', methods=['GET', 'POST'])
|
443 |
+
def upload_data_file():
|
444 |
+
try:
|
445 |
+
if request.method == 'POST':
|
446 |
+
if 'file' not in request.files:
|
447 |
+
flash('No file part', 'error')
|
448 |
+
return redirect(request.url)
|
449 |
+
|
450 |
+
file = request.files['file']
|
451 |
+
if file.filename == '':
|
452 |
+
flash('No selected file', 'error')
|
453 |
+
return redirect(request.url)
|
454 |
+
|
455 |
+
filename = secure_filename(file.filename)
|
456 |
+
file_path = os.path.join(app.config['DATA_FOLDER'], filename)
|
457 |
+
file.save(file_path)
|
458 |
+
|
459 |
+
flash(f'File {filename} uploaded/overwritten successfully!', 'success')
|
460 |
+
return redirect(url_for('show_data_files'))
|
461 |
+
|
462 |
+
except Exception as e:
|
463 |
+
flash(f"Error: {str(e)}", 'error')
|
464 |
+
return redirect(request.referrer)
|
465 |
+
|
466 |
+
@app.route('/data_files', methods=['GET'])
|
467 |
+
def show_data_files():
|
468 |
+
try:
|
469 |
+
files = os.listdir(app.config['DATA_FOLDER'])
|
470 |
+
return render_template('data_files.html', files=files)
|
471 |
+
|
472 |
+
except Exception as e:
|
473 |
+
flash(f"Error retrieving files: {str(e)}", 'error')
|
474 |
+
return redirect(url_for('index'))
|
475 |
+
|
476 |
+
@app.route('/download/<filename>', methods=['GET'])
|
477 |
+
def download_files(filename):
|
478 |
+
try:
|
479 |
+
file_path = os.path.join(app.config['DATA_FOLDER'], filename)
|
480 |
+
return send_file(file_path, as_attachment=True)
|
481 |
+
|
482 |
+
except Exception as e:
|
483 |
+
flash(f"Error downloading {filename}: {str(e)}", 'error')
|
484 |
+
return redirect(url_for('show_data_files'))
|
485 |
+
|
486 |
if __name__ == '__main__':
|
487 |
app.run(debug=True)
|
488 |
|