TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Navi-27/Proyecto-UPC/llms.txt
Use this file to discover all available pages before exploring further.
PokeAPI class in services/poke_api.py is the bridge between the application and the PokéAPI REST API. It implements a cache-first strategy using the local SQLite cache_pokemon table: network requests are only made when the cache is empty or when a specific Pokémon is not found in it. This dramatically reduces API call volume after the first run and keeps the application functional even during transient network outages.
Configuration
The root URL for all PokéAPI requests:
https://pokeapi.co/api/v2Cache-First Strategy
On every application startup, the index route callsapi.validacion() to decide how to populate the Pokédex:
- If
validacion()returnsFalse(cache is empty),obtener_lista_pokemones(limite=1025)is called. This makes 1 026 HTTP requests — one for the list endpoint and one per Pokémon — then persists everything tocache_pokemonviaPokedex.guardar_en_db(). - If
validacion()returnsTrue(cache is populated),cargar_desde_db()reads all rows from SQLite and constructsPokemonobjects with no network I/O whatsoever.
The initial population of the cache (1 025 Pokémon) prints progress to stdout
as
Descargando {i+1}/1025... for every Pokémon fetched. This output is
normal and expected — it only occurs once, before the cache is written.Method Reference
validacion() → bool
validacion() → bool
Checks whether the Query executedSource
cache_pokemon table contains any rows.True if COUNT(*) is greater than zero (cache is populated); False if the table is empty.cargar_desde_db() → Pokedex
cargar_desde_db() → Pokedex
Loads the entire Source
cache_pokemon table from SQLite and returns a fully populated Pokedex instance. This is the primary path for all requests after the first startup.A
Pokedex instance containing one Pokemon object per row in cache_pokemon. The tipos and stats columns are JSON strings in the database; this method deserializes them with json.loads before constructing each Pokemon.obtener_lista_pokemones(limite, offset=0) → Pokedex
obtener_lista_pokemones(limite, offset=0) → Pokedex
Fetches a batch of Pokémon from PokéAPI, constructs Endpoints calledwhere
Pokemon objects, persists them to the SQLite cache, and returns a populated Pokedex. This method is called only when the cache is empty.The number of Pokémon to fetch. The application always calls this with
limite=1025 to load the full National Pokédex.The starting index for pagination. Defaults to
0.A
Pokedex instance containing all fetched Pokémon, already persisted to cache_pokemon.GET https://pokeapi.co/api/v2/pokemon?limit={limite}&offset={offset}— retrieves a paginated list of Pokémon names and individual URLs.- For each result:
GET {item["url"]}— retrieves full data for that Pokémon.
numero = offset + i + 1 (the 1-based Pokédex position).Sourceobtener_pokemon(nombre_o_id) → Pokemon | None
obtener_pokemon(nombre_o_id) → Pokemon | None
Retrieves a single Pokémon by name or numeric ID. This is the most sophisticated method in the class — it implements a full cache-first lookup with a live API fallback and automatic cache population on miss.Lookup flowSource
The Pokémon’s lowercase name (e.g.
"pikachu") or its National Pokédex number (e.g. 25).A
Pokemon instance on success. Returns None if the Pokémon is not found in the cache, the API returns a non-200 status, or any exception is raised.obtener_por_tipo(tipo) → list[Pokemon]
obtener_por_tipo(tipo) → list[Pokemon]
Queries the SQLite cache for all Pokémon whose Query executedSource
tipos column contains the given type string, and returns them as a list of Pokemon objects.The type name to filter by (e.g.
"fire", "water", "dragon"). Case-sensitive — use lowercase to match stored values.A list of
Pokemon objects whose stored tipos JSON string contains the given type. Returns an empty list if no matches are found.