add statistics
This commit is contained in:
parent
23de80f94d
commit
ceb62b408a
6 changed files with 318 additions and 3 deletions
|
|
@ -1,7 +1,9 @@
|
|||
from flask import Flask, jsonify, render_template
|
||||
from flask_cors import CORS
|
||||
import sqlite3
|
||||
from datetime import datetime
|
||||
import sys
|
||||
import os
|
||||
from datetime import datetime, date
|
||||
|
||||
app = Flask(__name__)
|
||||
CORS(app)
|
||||
|
|
@ -9,6 +11,14 @@ CORS(app)
|
|||
# Путь к базе данных бота
|
||||
DB_PATH = "/app/data/lichess_bot.db"
|
||||
|
||||
# Add parent directory to path to import message_counters
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'LichessClientTG_bot'))
|
||||
try:
|
||||
from message_counters import MessageCounters
|
||||
except ImportError:
|
||||
# Fallback if import fails
|
||||
MessageCounters = None
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
"""Главная страница"""
|
||||
|
|
@ -60,11 +70,32 @@ def get_users():
|
|||
''')
|
||||
total_gamers = cursor.fetchone()[0]
|
||||
|
||||
# Get message counters statistics
|
||||
message_stats = {}
|
||||
if MessageCounters:
|
||||
try:
|
||||
counters = MessageCounters(db_path=DB_PATH)
|
||||
message_stats = counters.get_stats_summary()
|
||||
except Exception as e:
|
||||
print(f"Error getting message counters: {e}")
|
||||
message_stats = {
|
||||
'total_all_time': 0,
|
||||
'total_today': 0,
|
||||
'by_command': {}
|
||||
}
|
||||
else:
|
||||
message_stats = {
|
||||
'total_all_time': 0,
|
||||
'total_today': 0,
|
||||
'by_command': {}
|
||||
}
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'users': users,
|
||||
'total_users': len(users),
|
||||
'total_gamers': total_gamers
|
||||
'total_gamers': total_gamers,
|
||||
'message_stats': message_stats
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue