Odstranit z2/web_app.py
This commit is contained in:
parent
4b711488f4
commit
6d5cd85408
141
z2/web_app.py
141
z2/web_app.py
@ -1,141 +0,0 @@
|
|||||||
from flask import Flask, render_template_string, jsonify
|
|
||||||
import mysql.connector
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
|
|
||||||
DB_CONFIG = {
|
|
||||||
"host": "mysql",
|
|
||||||
"user": "root",
|
|
||||||
"password": "0674998280tanya",
|
|
||||||
"database": "telegram_bot"
|
|
||||||
}
|
|
||||||
|
|
||||||
TEMPLATE = """
|
|
||||||
<!doctype html>
|
|
||||||
<html lang="sk">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Zoznam porušovateľov</title>
|
|
||||||
<style>
|
|
||||||
* {
|
|
||||||
box-sizing: border-box;
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
min-height: 100vh;
|
|
||||||
width: 100vw;
|
|
||||||
background: url('/static/bg.png') no-repeat center center/cover;
|
|
||||||
backdrop-filter: blur(8px);
|
|
||||||
animation: rotateBackground 60s linear infinite;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
font-family: 'Segoe UI', sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes rotateBackground {
|
|
||||||
0% { background-position: 20% 20%; }
|
|
||||||
50% { background-position: 60% 60%; }
|
|
||||||
100% { background-position: 20% 20%; }
|
|
||||||
}
|
|
||||||
|
|
||||||
.container {
|
|
||||||
background-color: rgba(0, 0, 0, 0.6);
|
|
||||||
padding: 2rem 3rem;
|
|
||||||
border-radius: 12px;
|
|
||||||
box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
|
|
||||||
text-align: center;
|
|
||||||
color: white;
|
|
||||||
max-height: 90vh;
|
|
||||||
overflow-y: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
margin-bottom: 2rem;
|
|
||||||
font-size: 2.5rem;
|
|
||||||
text-shadow: 2px 2px 10px black;
|
|
||||||
}
|
|
||||||
|
|
||||||
table {
|
|
||||||
margin: 0 auto;
|
|
||||||
border-collapse: collapse;
|
|
||||||
}
|
|
||||||
|
|
||||||
th, td {
|
|
||||||
border: 1px solid #999;
|
|
||||||
padding: 1rem 2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
th {
|
|
||||||
background-color: rgba(255, 255, 255, 0.2);
|
|
||||||
}
|
|
||||||
|
|
||||||
td {
|
|
||||||
color: #eee;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
|
||||||
<h1>Zoznam porušovateľov</h1>
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr><th>Používateľ</th><th>Správa</th></tr>
|
|
||||||
</thead>
|
|
||||||
<tbody id="violators-body">
|
|
||||||
{% for row in data %}
|
|
||||||
<tr><td>{{ row[0] }}</td><td>{{ row[1] }}</td></tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
async function refreshTable() {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/data');
|
|
||||||
const data = await response.json();
|
|
||||||
const tbody = document.getElementById('violators-body');
|
|
||||||
tbody.innerHTML = '';
|
|
||||||
|
|
||||||
data.forEach(row => {
|
|
||||||
const tr = document.createElement('tr');
|
|
||||||
tr.innerHTML = `<td>${row[0]}</td><td>${row[1]}</td>`;
|
|
||||||
tbody.appendChild(tr);
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Nepodarilo sa načítať dáta:", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setInterval(refreshTable, 1000); // každých 5 sekúnd
|
|
||||||
window.onload = refreshTable;
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
"""
|
|
||||||
|
|
||||||
@app.route('/')
|
|
||||||
def index():
|
|
||||||
conn = mysql.connector.connect(**DB_CONFIG)
|
|
||||||
cursor = conn.cursor()
|
|
||||||
cursor.execute("SELECT username, message FROM violators ORDER BY id DESC")
|
|
||||||
data = cursor.fetchall()
|
|
||||||
cursor.close()
|
|
||||||
conn.close()
|
|
||||||
return render_template_string(TEMPLATE, data=data)
|
|
||||||
|
|
||||||
@app.route('/data')
|
|
||||||
def data():
|
|
||||||
conn = mysql.connector.connect(**DB_CONFIG)
|
|
||||||
cursor = conn.cursor()
|
|
||||||
cursor.execute("SELECT username, message FROM violators ORDER BY id DESC")
|
|
||||||
data = cursor.fetchall()
|
|
||||||
cursor.close()
|
|
||||||
conn.close()
|
|
||||||
return jsonify(data)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
app.run(host='0.0.0.0', port=5000)
|
|
Loading…
Reference in New Issue
Block a user