zmiany, temp maile, csv browser
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
import os
|
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
|
import pandas as pd
|
||||||
|
|
||||||
EXPORTS_DIR = "exports"
|
EXPORTS_DIR = "exports"
|
||||||
@ -9,38 +9,61 @@ app = Flask(__name__)
|
|||||||
|
|
||||||
TEMPLATE = """
|
TEMPLATE = """
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html data-bs-theme="dark">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>CSV Viewer</title>
|
<title>CSV Viewer</title>
|
||||||
<link rel="stylesheet"
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
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>
|
<!-- Bootstrap 5 -->
|
||||||
<script
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
|
<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>
|
</head>
|
||||||
<body>
|
<body class="bg-body text-body">
|
||||||
<h2>📂 CSV Viewer</h2>
|
|
||||||
|
<div class="container">
|
||||||
|
<h2>📊 CSV Viewer</h2>
|
||||||
|
|
||||||
{% if files %}
|
{% if files %}
|
||||||
<ul>
|
<div class="list-group mb-4">
|
||||||
{% for file in files %}
|
{% 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 %}
|
{% endfor %}
|
||||||
</ul>
|
</div>
|
||||||
{% else %}
|
{% 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 %}
|
{% endif %}
|
||||||
|
|
||||||
{% if table %}
|
{% if table %}
|
||||||
<hr>
|
<hr>
|
||||||
<h3>Plik: {{ filename }}</h3>
|
<h3 class="mt-4">Plik: {{ filename }}</h3>
|
||||||
|
<div class="table-responsive">
|
||||||
{{ table | safe }}
|
{{ table | safe }}
|
||||||
|
</div>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('#csv-table').DataTable();
|
$('#csv-table').DataTable();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
@ -48,7 +71,7 @@ TEMPLATE = """
|
|||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
files = [f for f in os.listdir(EXPORTS_DIR) if f.endswith(".csv")]
|
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")
|
@app.route("/view")
|
||||||
def view_file():
|
def view_file():
|
||||||
@ -61,7 +84,7 @@ def view_file():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
df = pd.read_csv(path)
|
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")]
|
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)
|
return render_template_string(TEMPLATE, files=files, table=html_table, filename=filename, dir=EXPORTS_DIR)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Reference in New Issue
Block a user