LichessStatTgWeb/test_kostik2811.py
2025-11-20 03:14:06 +03:00

80 lines
3 KiB
Python
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
Скрипт для тестирования запросов к Lichess API для пользователя kostik2811
"""
import asyncio
import sys
import os
# Добавляем пути к модулям
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'LichessWebServices'))
from lichess_client import LichessClient
from stats_service import StatsService
import logging
# Настройка логирования
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
async def test_kostik2811():
"""Тестирование запросов для kostik2811"""
username = "kostik2811"
logger.info(f"🔍 Тестирование запросов для пользователя: {username}")
# Тест 1: Прямой запрос к Lichess API
logger.info("\n" + "="*50)
logger.info("ТЕСТ 1: Прямой запрос к Lichess API")
logger.info("="*50)
lichess_client = LichessClient()
try:
activity_data = await lichess_client.get_user_activity(username)
if activity_data:
logger.info(f"✅ Получены данные активности: {len(activity_data)} записей")
for i, activity in enumerate(activity_data[:3]): # Показываем первые 3
logger.info(f" Активность {i+1}: {activity.get('interval', 'N/A')}")
else:
logger.warning(f"⚠️ Данные активности не получены (None или пусто)")
except Exception as e:
logger.error(f"❌ Ошибка при запросе к Lichess API: {e}")
import traceback
logger.error(traceback.format_exc())
finally:
await lichess_client.close()
# Тест 2: Запрос через StatsService
logger.info("\n" + "="*50)
logger.info("ТЕСТ 2: Запрос через StatsService.get_today_stats")
logger.info("="*50)
lichess_client2 = LichessClient()
stats_service = StatsService(lichess_client2)
try:
result = await stats_service.get_today_stats(username)
logger.info(f"✅ Результат StatsService: message={result.message}")
if result.data:
logger.info(f" Данные: username={result.data.username}")
logger.info(f" Задачи: {result.data.tasks}")
logger.info(f" Игры: {result.data.games}")
else:
logger.warning(f"⚠️ Нет данных в результате")
except Exception as e:
logger.error(f"❌ Ошибка в StatsService: {e}")
import traceback
logger.error(traceback.format_exc())
finally:
await lichess_client2.close()
logger.info("\n" + "="*50)
logger.info("Тестирование завершено")
logger.info("="*50)
if __name__ == "__main__":
asyncio.run(test_kostik2811())