tempora/web/app.py

35 lines
989 B
Python

import os
from flask import Flask, render_template
import psycopg2
app = Flask(__name__)
DB_CONFIG = {
'host': os.getenv("HOST"),
'port': os.getenv("PORT"),
'database': os.getenv("DBNAME"),
'user': os.getenv("USER"),
'password': os.getenv("PASSWORD")
}
@app.route("/")
def index():
with psycopg2.connect(**DB_CONFIG) as conn:
with conn.cursor() as cur:
cur.execute("SELECT source, message, created_at FROM leaks ORDER BY created_at DESC LIMIT 50")
leaks = cur.fetchall()
return render_template("index.html", leaks=leaks)
@app.route("/logs")
def logs():
log_path = os.path.join(os.path.dirname(__file__), '..', 'tg_nodes.log')
try:
with open(log_path, 'r', encoding='utf-8') as f:
lines = f.readlines()[-100:]
except FileNotFoundError:
lines = ["Лог-файл не найден"]
return render_template("logs.html", logs=lines)
if __name__ == "__main__":
app.run(debug=True)