- stats service: POST /users/status proxies Lichess POST /api/users (up to 300 names,
through the shared-token gate) -> disabled / seen_at / games_total (sum of perfs.*.games)
- bot: PlayerStatusRefresher refreshes all tracked players every 15 min (2 bulk calls for
~500 players) into the new gamer_status table
- periodic_check: before the games request, _decide_skip() compares the player's
games_total with the pair's stored baseline (user_gamers.last_games_total); unchanged
and no token -> no HTTP call, checkpoint advances only to what the status proves
(status.checked_at - 60s), so games finished between a refresh and the window end
are still reported next time. Closed account -> skip + one notice to the owner,
auto-resume when reopened.
- /getgamers and /delgamer mark closed accounts with ⛔
Background load drops from ~445 games/user calls per hour to ~8 bulk calls plus one
games call per player who actually played.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
||
|---|---|---|
| .. | ||
| API_DOCUMENTATION.md | ||
| Dockerfile | ||
| lichess_client.py | ||
| main.py | ||
| models.py | ||
| rate_limiter.py | ||
| README.md | ||
| requirements.txt | ||
| stats_service.py | ||
Lichess Statistics API
REST API сервис для получения статистики игроков Lichess.org по играм и решению задач.
Возможности
- Получение статистики за сегодняшний день
- Получение статистики за вчерашний день
- Получение статистики за последние 7 дней
- Поддержка режимов игры: Bullet, Blitz, Rapid
- Статистика по решению задач (пазлов)
- Расчет изменения рейтинга
- Подсчет побед, поражений и ничьих
Запуск с Docker
1. Сборка и запуск контейнера
# Сборка образа
docker-compose build
# Запуск сервиса
docker-compose up -d
2. Проверка работы
Сервис будет доступен по адресу: http://localhost:8000
- Документация API: http://localhost:8000/docs
- Проверка здоровья: http://localhost:8000/health
API Endpoints
Получить статистику за сегодня
GET /stats/{username}/today
Получить статистику за вчера
GET /stats/{username}/yesterday
Получить статистику за неделю
GET /stats/{username}/week
Примеры использования
Статистика за сегодня
curl http://localhost:8000/stats/vrubelroman/today
Статистика за вчера
curl http://localhost:8000/stats/vrubelroman/yesterday
Статистика за неделю
curl http://localhost:8000/stats/vrubelroman/week
Формат ответа
{
"message": "Статистика за сегодняшний день",
"data": {
"username": "vrubelroman",
"tasks": {
"total": 28,
"solved": 25,
"unsolved": 3
},
"games": {
"bullet": {
"games_played": 7,
"rating_change": 30,
"final_rating": 2320,
"wins": 5,
"losses": 0,
"draws": 0
},
"blitz": {
"games_played": 5,
"rating_change": 32,
"final_rating": 2224,
"wins": 5,
"losses": 0,
"draws": 0
},
"rapid": {
"games_played": 2,
"rating_change": -10,
"final_rating": 2210,
"wins": 1,
"losses": 1,
"draws": 0
}
}
}
}
Остановка сервиса
docker-compose down
Логи
Для просмотра логов:
docker-compose logs -f