zmiany, temp maile, csv browser
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import os
|
||||
from flask import Flask, render_template_string, send_from_directory, request
|
||||
from flask import Flask, render_template_string, request
|
||||
import pandas as pd
|
||||
|
||||
EXPORTS_DIR = "exports"
|
||||
@ -9,38 +9,61 @@ app = Flask(__name__)
|
||||
|
||||
TEMPLATE = """
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html data-bs-theme="dark">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>CSV Viewer</title>
|
||||
<link rel="stylesheet"
|
||||
href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css">
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script
|
||||
src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<!-- Bootstrap 5 -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
|
||||
<!-- DataTables -->
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/dataTables.bootstrap5.min.css">
|
||||
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.13.4/js/dataTables.bootstrap5.min.js"></script>
|
||||
|
||||
<style>
|
||||
body {
|
||||
padding: 2rem;
|
||||
}
|
||||
h2, h3 {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>📂 CSV Viewer</h2>
|
||||
<body class="bg-body text-body">
|
||||
|
||||
<div class="container">
|
||||
<h2>📊 CSV Viewer</h2>
|
||||
|
||||
{% if files %}
|
||||
<ul>
|
||||
<div class="list-group mb-4">
|
||||
{% for file in files %}
|
||||
<li><a href="/view?file={{ file }}">{{ file }}</a></li>
|
||||
<a href="/view?file={{ file }}" class="list-group-item list-group-item-action {% if file == filename %}active{% endif %}">
|
||||
{{ file }}
|
||||
</a>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% else %}
|
||||
<p>Brak plików w katalogu <code>{{ dir }}</code>.</p>
|
||||
<p class="text-warning">Brak plików w katalogu <code>{{ dir }}</code>.</p>
|
||||
{% endif %}
|
||||
|
||||
{% if table %}
|
||||
<hr>
|
||||
<h3>Plik: {{ filename }}</h3>
|
||||
<h3 class="mt-4">Plik: {{ filename }}</h3>
|
||||
<div class="table-responsive">
|
||||
{{ table | safe }}
|
||||
</div>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#csv-table').DataTable();
|
||||
});
|
||||
</script>
|
||||
{% endif %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
@ -48,7 +71,7 @@ TEMPLATE = """
|
||||
@app.route("/")
|
||||
def index():
|
||||
files = [f for f in os.listdir(EXPORTS_DIR) if f.endswith(".csv")]
|
||||
return render_template_string(TEMPLATE, files=files, table=None, dir=EXPORTS_DIR)
|
||||
return render_template_string(TEMPLATE, files=files, table=None, filename=None, dir=EXPORTS_DIR)
|
||||
|
||||
@app.route("/view")
|
||||
def view_file():
|
||||
@ -61,7 +84,7 @@ def view_file():
|
||||
|
||||
try:
|
||||
df = pd.read_csv(path)
|
||||
html_table = df.to_html(classes="display", index=False, table_id="csv-table")
|
||||
html_table = df.to_html(classes="table table-striped table-bordered display", index=False, table_id="csv-table")
|
||||
files = [f for f in os.listdir(EXPORTS_DIR) if f.endswith(".csv")]
|
||||
return render_template_string(TEMPLATE, files=files, table=html_table, filename=filename, dir=EXPORTS_DIR)
|
||||
except Exception as e:
|
||||
|
Reference in New Issue
Block a user