LichessStatTgWeb/LichessWebServices
vrubelroman 619c00aa06
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 12s
stop infinite retry loop on rejected Lichess tokens
A gamer's periodic check would get permanently stuck if their stored token
was revoked/expired: our stats API collapsed both "Lichess rejected the
token" (401/403, permanent) and genuine transient errors into the same 502
response, so the bot treated an invalid token exactly like a network blip —
retrying the same window forever at a capped 300s backoff, never advancing
the checkpoint (observed in prod: Dor1zz stuck for 100+ consecutive errors
over 8+ hours, admin alerts firing every 25 failures).

Preserve the distinction that already existed one layer down (lichess_client.py
already tells 401/403 apart from other failures) instead of collapsing it in
stats_service.py: add PuzzleOfPeriodResponse.auth_failed, have main.py return
401 specifically for that case, and have the bot raise a distinct
InvalidTokenError instead of returning None. On InvalidTokenError, the bot now
clears the token for that pair, notifies the user to reconnect via /addtoken,
and continues tracking games normally instead of stalling forever.
2026-07-05 07:37:14 +00:00
..
API_DOCUMENTATION.md Создание единого проекта Lichess Statistics Ecosystem 2025-10-26 20:23:26 +03:00
Dockerfile Создание единого проекта Lichess Statistics Ecosystem 2025-10-26 20:23:26 +03:00
lichess_client.py add per-game accuracy and outcome table to stats/notifications 2026-07-03 09:38:51 +00:00
main.py stop infinite retry loop on rejected Lichess tokens 2026-07-05 07:37:14 +00:00
models.py stop infinite retry loop on rejected Lichess tokens 2026-07-05 07:37:14 +00:00
rate_limiter.py rate limiter 0.2 sec 2025-11-18 15:10:19 +03:00
README.md Создание единого проекта Lichess Statistics Ecosystem 2025-10-26 20:23:26 +03:00
requirements.txt Создание единого проекта Lichess Statistics Ecosystem 2025-10-26 20:23:26 +03:00
stats_service.py stop infinite retry loop on rejected Lichess tokens 2026-07-05 07:37:14 +00:00

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 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