Создание единого проекта Lichess Statistics Ecosystem
- Объединены три проекта в один репозиторий - LichessWebServices - REST API для статистики - LichessClientTG_bot - Telegram бот с поддержкой множества пользователей - LichessWebView - Веб-интерфейс для просмотра пользователей и игроков - Добавлен общий docker-compose.yml для запуска всех сервисов - Добавлен скрипт start.sh для удобного запуска - Добавлен README с полным описанием проекта
This commit is contained in:
commit
a08fc8c962
32 changed files with 4990 additions and 0 deletions
116
LichessWebView/app.py
Normal file
116
LichessWebView/app.py
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
from flask import Flask, jsonify, render_template
|
||||
from flask_cors import CORS
|
||||
import sqlite3
|
||||
from datetime import datetime
|
||||
|
||||
app = Flask(__name__)
|
||||
CORS(app)
|
||||
|
||||
# Путь к базе данных бота
|
||||
DB_PATH = "/app/data/lichess_bot.db"
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
"""Главная страница"""
|
||||
return render_template('index.html')
|
||||
|
||||
@app.route('/api/users')
|
||||
def get_users():
|
||||
"""Получить всех пользователей"""
|
||||
try:
|
||||
with sqlite3.connect(DB_PATH) as conn:
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Получаем всех пользователей
|
||||
cursor.execute('''
|
||||
SELECT
|
||||
tu.user_id,
|
||||
tu.username,
|
||||
tu.first_name,
|
||||
tu.last_name,
|
||||
tu.created_at,
|
||||
COUNT(ug.id) as gamer_count,
|
||||
SUM(CASE WHEN ug.is_active = 1 THEN 1 ELSE 0 END) as active_gamers,
|
||||
SUM(CASE WHEN ug.period_minutes > 0 THEN 1 ELSE 0 END) as monitored_gamers
|
||||
FROM telegram_users tu
|
||||
LEFT JOIN user_gamers ug ON tu.user_id = ug.user_id
|
||||
GROUP BY tu.user_id, tu.username, tu.first_name, tu.last_name, tu.created_at
|
||||
ORDER BY COALESCE(tu.first_name, tu.username, '')
|
||||
''')
|
||||
|
||||
rows = cursor.fetchall()
|
||||
users = []
|
||||
|
||||
for row in rows:
|
||||
users.append({
|
||||
'user_id': row[0],
|
||||
'username': row[1] or '-',
|
||||
'first_name': row[2] or '-',
|
||||
'last_name': row[3],
|
||||
'created_at': row[4],
|
||||
'gamer_count': row[5],
|
||||
'active_gamers': row[6],
|
||||
'monitored_gamers': row[7]
|
||||
})
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'users': users,
|
||||
'total': len(users)
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': str(e)
|
||||
}), 500
|
||||
|
||||
@app.route('/api/users/<int:user_id>/gamers')
|
||||
def get_user_gamers(user_id):
|
||||
"""Получить игроков конкретного пользователя"""
|
||||
try:
|
||||
with sqlite3.connect(DB_PATH) as conn:
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Получаем игроков пользователя
|
||||
cursor.execute('''
|
||||
SELECT
|
||||
g.id,
|
||||
g.username,
|
||||
g.token,
|
||||
ug.is_active,
|
||||
ug.period_minutes,
|
||||
ug.created_at
|
||||
FROM user_gamers ug
|
||||
JOIN gamers g ON ug.gamer_id = g.id
|
||||
WHERE ug.user_id = ?
|
||||
ORDER BY g.username
|
||||
''', (user_id,))
|
||||
|
||||
rows = cursor.fetchall()
|
||||
gamers = []
|
||||
|
||||
for row in rows:
|
||||
gamers.append({
|
||||
'id': row[0],
|
||||
'username': row[1],
|
||||
'has_token': bool(row[2]),
|
||||
'is_active': bool(row[3]),
|
||||
'period_minutes': row[4],
|
||||
'created_at': row[5]
|
||||
})
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'gamers': gamers
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': str(e)
|
||||
}), 500
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=5000, debug=True)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue