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>
 | 
					 | 
				
			||||||
    <script
 | 
					 | 
				
			||||||
        src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
 | 
					 | 
				
			||||||
</head>
 | 
					 | 
				
			||||||
<body>
 | 
					 | 
				
			||||||
    <h2>📂 CSV Viewer</h2>
 | 
					 | 
				
			||||||
    {% if files %}
 | 
					 | 
				
			||||||
        <ul>
 | 
					 | 
				
			||||||
        {% for file in files %}
 | 
					 | 
				
			||||||
            <li><a href="/view?file={{ file }}">{{ file }}</a></li>
 | 
					 | 
				
			||||||
        {% endfor %}
 | 
					 | 
				
			||||||
        </ul>
 | 
					 | 
				
			||||||
    {% else %}
 | 
					 | 
				
			||||||
        <p>Brak plików w katalogu <code>{{ dir }}</code>.</p>
 | 
					 | 
				
			||||||
    {% endif %}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    {% if table %}
 | 
					    <!-- Bootstrap 5 -->
 | 
				
			||||||
        <hr>
 | 
					    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
 | 
				
			||||||
        <h3>Plik: {{ filename }}</h3>
 | 
					    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
 | 
				
			||||||
        {{ table | safe }}
 | 
					
 | 
				
			||||||
        <script>
 | 
					    <!-- DataTables -->
 | 
				
			||||||
            $(document).ready(function() {
 | 
					    <link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/dataTables.bootstrap5.min.css">
 | 
				
			||||||
                $('#csv-table').DataTable();
 | 
					    <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>
 | 
					    <script src="https://cdn.datatables.net/1.13.4/js/dataTables.bootstrap5.min.js"></script>
 | 
				
			||||||
    {% endif %}
 | 
					
 | 
				
			||||||
 | 
					    <style>
 | 
				
			||||||
 | 
					        body {
 | 
				
			||||||
 | 
					            padding: 2rem;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        h2, h3 {
 | 
				
			||||||
 | 
					            margin-bottom: 1rem;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    </style>
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					<body class="bg-body text-body">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <div class="container">
 | 
				
			||||||
 | 
					        <h2>📊 CSV Viewer</h2>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        {% if files %}
 | 
				
			||||||
 | 
					            <div class="list-group mb-4">
 | 
				
			||||||
 | 
					                {% for file in files %}
 | 
				
			||||||
 | 
					                    <a href="/view?file={{ file }}" class="list-group-item list-group-item-action {% if file == filename %}active{% endif %}">
 | 
				
			||||||
 | 
					                        {{ file }}
 | 
				
			||||||
 | 
					                    </a>
 | 
				
			||||||
 | 
					                {% endfor %}
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					        {% else %}
 | 
				
			||||||
 | 
					            <p class="text-warning">Brak plików w katalogu <code>{{ dir }}</code>.</p>
 | 
				
			||||||
 | 
					        {% endif %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        {% if table %}
 | 
				
			||||||
 | 
					            <hr>
 | 
				
			||||||
 | 
					            <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>
 | 
					</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