Skip to main content
Glama
stats.py6.77 kB
"""Show statistics functionality (favorited, played, watched).""" from typing import Literal, overload from config.api import DEFAULT_LIMIT, DEFAULT_MAX_PAGES from config.endpoints import TRAKT_ENDPOINTS from models.types import FavoritedShowWrapper, PlayedShowWrapper, WatchedShowWrapper from models.types.pagination import PaginatedResponse from utils.api.errors import handle_api_errors from ..base import BaseClient class ShowStatsClient(BaseClient): """Client for show statistics operations.""" @overload async def get_favorited_shows( self, limit: int = DEFAULT_LIMIT, period: Literal["daily", "weekly", "monthly", "yearly", "all"] = "weekly", page: None = None, max_pages: int = DEFAULT_MAX_PAGES, ) -> list[FavoritedShowWrapper]: ... @overload async def get_favorited_shows( self, limit: int = DEFAULT_LIMIT, period: Literal["daily", "weekly", "monthly", "yearly", "all"] = "weekly", page: int = ..., max_pages: int = DEFAULT_MAX_PAGES, ) -> PaginatedResponse[FavoritedShowWrapper]: ... @handle_api_errors async def get_favorited_shows( self, limit: int = DEFAULT_LIMIT, period: Literal["daily", "weekly", "monthly", "yearly", "all"] = "weekly", page: int | None = None, max_pages: int = DEFAULT_MAX_PAGES, ) -> list[FavoritedShowWrapper] | PaginatedResponse[FavoritedShowWrapper]: """Get favorited shows from Trakt. Args: limit: Items per page period: Time period for favorited shows page: Page number (optional). If None, returns all results via auto-pagination. max_pages: Maximum number of pages to fetch when auto-paginating Returns: If page is None: List of all favorited shows across all pages (up to max_pages) If page specified: Paginated response with metadata for that page Raises: RuntimeError: If auto-pagination reaches max_pages without completing. """ if page is None: return await self.auto_paginate( TRAKT_ENDPOINTS["shows_favorited"], response_type=FavoritedShowWrapper, params={"limit": limit, "period": period}, max_pages=max_pages, ) # Single page with metadata return await self._make_paginated_request( TRAKT_ENDPOINTS["shows_favorited"], response_type=FavoritedShowWrapper, params={"page": page, "limit": limit, "period": period}, ) @overload async def get_played_shows( self, limit: int = DEFAULT_LIMIT, period: Literal["daily", "weekly", "monthly", "yearly", "all"] = "weekly", page: None = None, max_pages: int = DEFAULT_MAX_PAGES, ) -> list[PlayedShowWrapper]: ... @overload async def get_played_shows( self, limit: int = DEFAULT_LIMIT, period: Literal["daily", "weekly", "monthly", "yearly", "all"] = "weekly", page: int = ..., max_pages: int = DEFAULT_MAX_PAGES, ) -> PaginatedResponse[PlayedShowWrapper]: ... @handle_api_errors async def get_played_shows( self, limit: int = DEFAULT_LIMIT, period: Literal["daily", "weekly", "monthly", "yearly", "all"] = "weekly", page: int | None = None, max_pages: int = DEFAULT_MAX_PAGES, ) -> list[PlayedShowWrapper] | PaginatedResponse[PlayedShowWrapper]: """Get played shows from Trakt. Args: limit: Items per page period: Time period for played shows page: Page number (optional). If None, returns all results via auto-pagination. max_pages: Maximum number of pages to fetch when auto-paginating Returns: If page is None: List of all played shows across all pages (up to max_pages) If page specified: Paginated response with metadata for that page Raises: RuntimeError: If auto-pagination reaches max_pages without completing. """ if page is None: return await self.auto_paginate( TRAKT_ENDPOINTS["shows_played"], response_type=PlayedShowWrapper, params={"limit": limit, "period": period}, max_pages=max_pages, ) # Single page with metadata return await self._make_paginated_request( TRAKT_ENDPOINTS["shows_played"], response_type=PlayedShowWrapper, params={"page": page, "limit": limit, "period": period}, ) @overload async def get_watched_shows( self, limit: int = DEFAULT_LIMIT, period: Literal["daily", "weekly", "monthly", "yearly", "all"] = "weekly", page: None = None, max_pages: int = DEFAULT_MAX_PAGES, ) -> list[WatchedShowWrapper]: ... @overload async def get_watched_shows( self, limit: int = DEFAULT_LIMIT, period: Literal["daily", "weekly", "monthly", "yearly", "all"] = "weekly", page: int = ..., max_pages: int = DEFAULT_MAX_PAGES, ) -> PaginatedResponse[WatchedShowWrapper]: ... @handle_api_errors async def get_watched_shows( self, limit: int = DEFAULT_LIMIT, period: Literal["daily", "weekly", "monthly", "yearly", "all"] = "weekly", page: int | None = None, max_pages: int = DEFAULT_MAX_PAGES, ) -> list[WatchedShowWrapper] | PaginatedResponse[WatchedShowWrapper]: """Get watched shows from Trakt. Args: limit: Items per page period: Time period for watched shows page: Page number (optional). If None, returns all results via auto-pagination. max_pages: Maximum number of pages to fetch when auto-paginating Returns: If page is None: List of all watched shows across all pages (up to max_pages) If page specified: Paginated response with metadata for that page Raises: RuntimeError: If auto-pagination reaches max_pages without completing. """ if page is None: return await self.auto_paginate( TRAKT_ENDPOINTS["shows_watched"], response_type=WatchedShowWrapper, params={"limit": limit, "period": period}, max_pages=max_pages, ) # Single page with metadata return await self._make_paginated_request( TRAKT_ENDPOINTS["shows_watched"], response_type=WatchedShowWrapper, params={"page": page, "limit": limit, "period": period}, )

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wwiens/trakt_mcpserver'

If you have feedback or need assistance with the MCP directory API, please join our Discord server