добавлена проверка на существование добавляемого игрока

This commit is contained in:
vrubelroman 2025-11-07 22:54:49 +03:00
parent a5d6481495
commit ecd252cdad
2 changed files with 45 additions and 18 deletions

View file

@ -118,6 +118,25 @@ class LichessAPI:
logger.error(f"Error getting puzzles period: {e}")
return None
async def check_user_exists(self, username: str) -> bool:
"""Check if user exists on Lichess"""
try:
async with aiohttp.ClientSession() as session:
async with session.get(
f"{self.lichess_base_url}/user/{username}"
) as response:
if response.status == 200:
return True
elif response.status == 404:
logger.warning(f"User {username} not found on Lichess (404)")
return False
else:
logger.error(f"Failed to check user existence: {response.status}")
return False
except Exception as e:
logger.error(f"Error checking user existence: {e}")
return False
async def get_user_ratings(self, username: str) -> Optional[Dict[str, Any]]:
"""Get user ratings from Lichess API"""
try: