localdex 0.1.8__py3-none-any.whl → 0.1.19__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- localdex/__init__.py +4 -11
- localdex/core.py +187 -2
- localdex/random_battles.py +251 -0
- localdex/sprite_downloader.py +932 -0
- {localdex-0.1.8.dist-info → localdex-0.1.19.dist-info}/METADATA +165 -7
- {localdex-0.1.8.dist-info → localdex-0.1.19.dist-info}/RECORD +9 -7
- {localdex-0.1.8.dist-info → localdex-0.1.19.dist-info}/WHEEL +0 -0
- {localdex-0.1.8.dist-info → localdex-0.1.19.dist-info}/entry_points.txt +0 -0
- {localdex-0.1.8.dist-info → localdex-0.1.19.dist-info}/top_level.txt +0 -0
localdex/__init__.py
CHANGED
@@ -1,18 +1,9 @@
|
|
1
|
-
"""
|
2
|
-
LocalDex - A fast, offline-first Python library for Pokemon data access.
|
3
|
-
|
4
|
-
This package provides comprehensive Pokemon information without requiring
|
5
|
-
network requests, making it perfect for applications that need reliable,
|
6
|
-
fast access to Pokemon data.
|
7
|
-
"""
|
8
|
-
|
9
|
-
__version__ = "0.1.0"
|
10
|
-
__author__ = "LocalDex Team"
|
11
|
-
__email__ = "localdex@example.com"
|
12
1
|
|
13
2
|
from .core import LocalDex
|
14
3
|
from .models import Pokemon, Move, Ability, Item, BaseStats
|
15
4
|
from .exceptions import PokemonNotFoundError, MoveNotFoundError, AbilityNotFoundError, ItemNotFoundError
|
5
|
+
from .random_battles import RandomBattleSets
|
6
|
+
from .sprite_downloader import SpriteDownloader
|
16
7
|
|
17
8
|
__all__ = [
|
18
9
|
"LocalDex",
|
@@ -25,4 +16,6 @@ __all__ = [
|
|
25
16
|
"MoveNotFoundError",
|
26
17
|
"AbilityNotFoundError",
|
27
18
|
"ItemNotFoundError",
|
19
|
+
"RandomBattleSets",
|
20
|
+
"SpriteDownloader",
|
28
21
|
]
|
localdex/core.py
CHANGED
@@ -18,6 +18,8 @@ from .exceptions import (
|
|
18
18
|
ItemNotFoundError, DataLoadError, SearchError
|
19
19
|
)
|
20
20
|
from .data_loader import DataLoader
|
21
|
+
from .random_battles import RandomBattleSets
|
22
|
+
from .sprite_downloader import SpriteDownloader
|
21
23
|
|
22
24
|
|
23
25
|
class LocalDex:
|
@@ -29,7 +31,7 @@ class LocalDex:
|
|
29
31
|
performance and comprehensive search capabilities.
|
30
32
|
"""
|
31
33
|
|
32
|
-
def __init__(self, data_path: Optional[str] = None, data_dir: Optional[str] = None, enable_caching: bool = True):
|
34
|
+
def __init__(self, data_path: Optional[str] = None, data_dir: Optional[str] = None, enable_caching: bool = True, enable_random_battles: bool = True, enable_sprite_downloader: bool = True, sprite_max_workers: int = 8):
|
33
35
|
"""
|
34
36
|
Initialize the LocalDex.
|
35
37
|
|
@@ -37,6 +39,9 @@ class LocalDex:
|
|
37
39
|
data_path: Optional path to data directory. If None, uses package data.
|
38
40
|
data_dir: Alias for data_path for backward compatibility.
|
39
41
|
enable_caching: Whether to enable caching for better performance.
|
42
|
+
enable_random_battles: Whether to enable random battle sets functionality.
|
43
|
+
enable_sprite_downloader: Whether to enable sprite downloader functionality.
|
44
|
+
sprite_max_workers: Maximum number of worker threads for parallel sprite processing.
|
40
45
|
"""
|
41
46
|
# Use data_dir if provided, otherwise use data_path
|
42
47
|
final_data_path = data_dir if data_dir is not None else data_path
|
@@ -44,6 +49,12 @@ class LocalDex:
|
|
44
49
|
self.data_dir = final_data_path # Store for backward compatibility
|
45
50
|
self.enable_caching = enable_caching
|
46
51
|
|
52
|
+
# Sprite downloader integration
|
53
|
+
self.sprite_downloader = SpriteDownloader(final_data_path, max_workers=sprite_max_workers) if enable_sprite_downloader else None
|
54
|
+
|
55
|
+
# Initialize random battle sets
|
56
|
+
self.random_battles = RandomBattleSets() if enable_random_battles else None
|
57
|
+
|
47
58
|
# Initialize caches
|
48
59
|
self._pokemon_cache: Dict[str, Pokemon] = {}
|
49
60
|
self._pokemon_id_cache: Dict[int, Pokemon] = {}
|
@@ -556,4 +567,178 @@ class LocalDex:
|
|
556
567
|
"moves": len(self._move_cache),
|
557
568
|
"abilities": len(self._ability_cache),
|
558
569
|
"items": len(self._item_cache)
|
559
|
-
}
|
570
|
+
}
|
571
|
+
|
572
|
+
# Random Battle Sets Methods
|
573
|
+
|
574
|
+
def get_random_battle_sets(self, pokemon_name: str, generation: int = 9, force_refresh: bool = False) -> Optional[Dict[str, Any]]:
|
575
|
+
"""
|
576
|
+
Get random battle sets for a specific Pokemon.
|
577
|
+
|
578
|
+
Args:
|
579
|
+
pokemon_name: Name of the Pokemon (case-insensitive)
|
580
|
+
generation: Generation to get sets from (8 or 9)
|
581
|
+
force_refresh: If True, re-download data
|
582
|
+
|
583
|
+
Returns:
|
584
|
+
Pokemon's random battle sets or None if not found
|
585
|
+
|
586
|
+
Raises:
|
587
|
+
ValueError: If random battles are not enabled
|
588
|
+
"""
|
589
|
+
if self.random_battles is None:
|
590
|
+
raise ValueError("Random battle sets are not enabled. Set enable_random_battles=True when initializing LocalDex.")
|
591
|
+
|
592
|
+
if generation == 9:
|
593
|
+
return self.random_battles.get_pokemon_gen9_sets(pokemon_name, force_refresh)
|
594
|
+
elif generation == 8:
|
595
|
+
return self.random_battles.get_pokemon_gen8_data(pokemon_name, force_refresh)
|
596
|
+
else:
|
597
|
+
raise ValueError(f"Generation {generation} is not supported. Use 8 or 9.")
|
598
|
+
|
599
|
+
def get_all_random_battle_sets(self, generation: int = 9, force_refresh: bool = False) -> Dict[str, Any]:
|
600
|
+
"""
|
601
|
+
Get all random battle sets for a generation.
|
602
|
+
|
603
|
+
Args:
|
604
|
+
generation: Generation to get sets from (8 or 9)
|
605
|
+
force_refresh: If True, re-download data
|
606
|
+
|
607
|
+
Returns:
|
608
|
+
Dictionary containing all random battle sets for the generation
|
609
|
+
|
610
|
+
Raises:
|
611
|
+
ValueError: If random battles are not enabled
|
612
|
+
"""
|
613
|
+
if self.random_battles is None:
|
614
|
+
raise ValueError("Random battle sets are not enabled. Set enable_random_battles=True when initializing LocalDex.")
|
615
|
+
|
616
|
+
if generation == 9:
|
617
|
+
return self.random_battles.get_gen9_sets(force_refresh)
|
618
|
+
elif generation == 8:
|
619
|
+
return self.random_battles.get_gen8_data(force_refresh)
|
620
|
+
else:
|
621
|
+
raise ValueError(f"Generation {generation} is not supported. Use 8 or 9.")
|
622
|
+
|
623
|
+
def search_random_battle_pokemon_by_move(self, move_name: str, generation: int = 9, force_refresh: bool = False) -> List[str]:
|
624
|
+
"""
|
625
|
+
Search for Pokemon that have a specific move in their random battle sets.
|
626
|
+
|
627
|
+
Args:
|
628
|
+
move_name: Name of the move to search for (case-insensitive)
|
629
|
+
generation: Generation to search in (8 or 9)
|
630
|
+
force_refresh: If True, re-download data
|
631
|
+
|
632
|
+
Returns:
|
633
|
+
List of Pokemon names that have the move
|
634
|
+
|
635
|
+
Raises:
|
636
|
+
ValueError: If random battles are not enabled
|
637
|
+
"""
|
638
|
+
if self.random_battles is None:
|
639
|
+
raise ValueError("Random battle sets are not enabled. Set enable_random_battles=True when initializing LocalDex.")
|
640
|
+
|
641
|
+
return self.random_battles.search_pokemon_by_move(move_name, generation, force_refresh)
|
642
|
+
|
643
|
+
def search_random_battle_pokemon_by_ability(self, ability_name: str, generation: int = 9, force_refresh: bool = False) -> List[str]:
|
644
|
+
"""
|
645
|
+
Search for Pokemon that have a specific ability in their random battle sets.
|
646
|
+
|
647
|
+
Args:
|
648
|
+
ability_name: Name of the ability to search for (case-insensitive)
|
649
|
+
generation: Generation to search in (8 or 9)
|
650
|
+
force_refresh: If True, re-download data
|
651
|
+
|
652
|
+
Returns:
|
653
|
+
List of Pokemon names that have the ability
|
654
|
+
|
655
|
+
Raises:
|
656
|
+
ValueError: If random battles are not enabled
|
657
|
+
"""
|
658
|
+
if self.random_battles is None:
|
659
|
+
raise ValueError("Random battle sets are not enabled. Set enable_random_battles=True when initializing LocalDex.")
|
660
|
+
|
661
|
+
return self.random_battles.search_pokemon_by_ability(ability_name, generation, force_refresh)
|
662
|
+
|
663
|
+
def get_available_random_battle_generations(self) -> List[int]:
|
664
|
+
"""
|
665
|
+
Get list of available generations for random battles.
|
666
|
+
|
667
|
+
Returns:
|
668
|
+
List of generation numbers
|
669
|
+
|
670
|
+
Raises:
|
671
|
+
ValueError: If random battles are not enabled
|
672
|
+
"""
|
673
|
+
if self.random_battles is None:
|
674
|
+
raise ValueError("Random battle sets are not enabled. Set enable_random_battles=True when initializing LocalDex.")
|
675
|
+
|
676
|
+
return self.random_battles.get_available_generations()
|
677
|
+
|
678
|
+
def get_random_battle_formats(self, generation: int) -> List[str]:
|
679
|
+
"""
|
680
|
+
Get available formats for a specific generation.
|
681
|
+
|
682
|
+
Args:
|
683
|
+
generation: Generation number
|
684
|
+
|
685
|
+
Returns:
|
686
|
+
List of available format names
|
687
|
+
|
688
|
+
Raises:
|
689
|
+
ValueError: If random battles are not enabled
|
690
|
+
"""
|
691
|
+
if self.random_battles is None:
|
692
|
+
raise ValueError("Random battle sets are not enabled. Set enable_random_battles=True when initializing LocalDex.")
|
693
|
+
|
694
|
+
return self.random_battles.get_generation_formats(generation)
|
695
|
+
|
696
|
+
def clear_random_battle_cache(self) -> None:
|
697
|
+
"""Clear random battle cache."""
|
698
|
+
if self.random_battles is not None:
|
699
|
+
self.random_battles.clear_cache()
|
700
|
+
|
701
|
+
def cleanup_random_battle_downloads(self) -> None:
|
702
|
+
"""Remove downloaded Pokemon Showdown repository."""
|
703
|
+
if self.random_battles is not None:
|
704
|
+
self.random_battles.cleanup_downloads()
|
705
|
+
|
706
|
+
def download_all_sprites(self):
|
707
|
+
"""
|
708
|
+
Download and extract all sprites (Pokemon and items).
|
709
|
+
"""
|
710
|
+
if not self.sprite_downloader:
|
711
|
+
raise RuntimeError("SpriteDownloader is not enabled.")
|
712
|
+
return self.sprite_downloader.download_all_sprites()
|
713
|
+
|
714
|
+
def get_pokemon_sprite_path(self, pokemon_name: str):
|
715
|
+
"""
|
716
|
+
Get the path to a Pokemon sprite image.
|
717
|
+
"""
|
718
|
+
if not self.sprite_downloader:
|
719
|
+
raise RuntimeError("SpriteDownloader is not enabled.")
|
720
|
+
return self.sprite_downloader.get_pokemon_sprite_path(pokemon_name)
|
721
|
+
|
722
|
+
def get_item_sprite_path(self, item_name: str):
|
723
|
+
"""
|
724
|
+
Get the path to an item sprite image.
|
725
|
+
"""
|
726
|
+
if not self.sprite_downloader:
|
727
|
+
raise RuntimeError("SpriteDownloader is not enabled.")
|
728
|
+
return self.sprite_downloader.get_item_sprite_path(item_name)
|
729
|
+
|
730
|
+
def get_sprite_metadata(self, sprite_type: str = "pokemon"):
|
731
|
+
"""
|
732
|
+
Get sprite metadata for either 'pokemon' or 'items'.
|
733
|
+
"""
|
734
|
+
if not self.sprite_downloader:
|
735
|
+
raise RuntimeError("SpriteDownloader is not enabled.")
|
736
|
+
return self.sprite_downloader.get_sprite_metadata(sprite_type)
|
737
|
+
|
738
|
+
def list_available_sprites(self, sprite_type: str = "pokemon"):
|
739
|
+
"""
|
740
|
+
List all available sprites of a given type ('pokemon' or 'items').
|
741
|
+
"""
|
742
|
+
if not self.sprite_downloader:
|
743
|
+
raise RuntimeError("SpriteDownloader is not enabled.")
|
744
|
+
return self.sprite_downloader.list_available_sprites(sprite_type)
|
@@ -0,0 +1,251 @@
|
|
1
|
+
"""
|
2
|
+
Random Battle Sets functionality for LocalDex.
|
3
|
+
|
4
|
+
This module provides functionality to download and parse Pokemon Showdown's
|
5
|
+
random battle sets from different generations and formats.
|
6
|
+
"""
|
7
|
+
|
8
|
+
import json
|
9
|
+
import os
|
10
|
+
import tempfile
|
11
|
+
from typing import Dict, List, Optional, Any, Union
|
12
|
+
from urllib.request import urlopen
|
13
|
+
|
14
|
+
from .exceptions import DataLoadError
|
15
|
+
|
16
|
+
|
17
|
+
class RandomBattleSets:
|
18
|
+
"""
|
19
|
+
Handles downloading and parsing Pokemon Showdown random battle sets.
|
20
|
+
|
21
|
+
This class provides methods to download random battle data from the
|
22
|
+
pkmn.github.io/randbats API and parse it into a usable format.
|
23
|
+
"""
|
24
|
+
|
25
|
+
# URLs for random battle data
|
26
|
+
GEN8_URL = "https://pkmn.github.io/randbats/data/gen8randombattle.json"
|
27
|
+
GEN9_URL = "https://pkmn.github.io/randbats/data/gen9randombattle.json"
|
28
|
+
|
29
|
+
def __init__(self, cache_dir: Optional[str] = None):
|
30
|
+
"""
|
31
|
+
Initialize the RandomBattleSets handler.
|
32
|
+
|
33
|
+
Args:
|
34
|
+
cache_dir: Directory to cache downloaded data. If None, uses temp directory.
|
35
|
+
"""
|
36
|
+
self.cache_dir = cache_dir or os.path.join(tempfile.gettempdir(), "localdex_random_battles")
|
37
|
+
|
38
|
+
# Ensure cache directory exists
|
39
|
+
os.makedirs(self.cache_dir, exist_ok=True)
|
40
|
+
|
41
|
+
# Cache for loaded data
|
42
|
+
self._gen9_sets_cache: Optional[Dict[str, Any]] = None
|
43
|
+
self._gen8_data_cache: Optional[Dict[str, Any]] = None
|
44
|
+
|
45
|
+
def _download_json_data(self, url: str, cache_file: str, force_refresh: bool = False) -> Dict[str, Any]:
|
46
|
+
"""
|
47
|
+
Download JSON data from URL and cache it locally.
|
48
|
+
|
49
|
+
Args:
|
50
|
+
url: URL to download from
|
51
|
+
cache_file: Local cache file path
|
52
|
+
force_refresh: If True, re-download even if already cached
|
53
|
+
|
54
|
+
Returns:
|
55
|
+
Downloaded data as dictionary
|
56
|
+
|
57
|
+
Raises:
|
58
|
+
DataLoadError: If download fails
|
59
|
+
"""
|
60
|
+
# Check if we have cached data and don't need to refresh
|
61
|
+
if os.path.exists(cache_file) and not force_refresh:
|
62
|
+
try:
|
63
|
+
with open(cache_file, 'r', encoding='utf-8') as f:
|
64
|
+
return json.load(f)
|
65
|
+
except (json.JSONDecodeError, IOError):
|
66
|
+
# If cache is corrupted, remove it and re-download
|
67
|
+
pass
|
68
|
+
|
69
|
+
try:
|
70
|
+
print(f"Downloading random battle data from {url}...")
|
71
|
+
with urlopen(url) as response:
|
72
|
+
data = json.loads(response.read().decode('utf-8'))
|
73
|
+
|
74
|
+
# Cache the data
|
75
|
+
with open(cache_file, 'w', encoding='utf-8') as f:
|
76
|
+
json.dump(data, f, indent=2)
|
77
|
+
|
78
|
+
print("Random battle data downloaded successfully!")
|
79
|
+
return data
|
80
|
+
|
81
|
+
except Exception as e:
|
82
|
+
raise DataLoadError(f"Failed to download data from {url}: {e}")
|
83
|
+
|
84
|
+
def get_gen9_sets(self, force_refresh: bool = False) -> Dict[str, Any]:
|
85
|
+
"""
|
86
|
+
Get Generation 9 random battle sets.
|
87
|
+
|
88
|
+
Args:
|
89
|
+
force_refresh: If True, re-download data
|
90
|
+
|
91
|
+
Returns:
|
92
|
+
Dictionary containing Gen 9 random battle sets
|
93
|
+
"""
|
94
|
+
if self._gen9_sets_cache is not None and not force_refresh:
|
95
|
+
return self._gen9_sets_cache
|
96
|
+
|
97
|
+
cache_file = os.path.join(self.cache_dir, "gen9_randombattle.json")
|
98
|
+
data = self._download_json_data(self.GEN9_URL, cache_file, force_refresh)
|
99
|
+
|
100
|
+
self._gen9_sets_cache = data
|
101
|
+
return data
|
102
|
+
|
103
|
+
def get_gen8_data(self, force_refresh: bool = False) -> Dict[str, Any]:
|
104
|
+
"""
|
105
|
+
Get Generation 8 random battle data.
|
106
|
+
|
107
|
+
Args:
|
108
|
+
force_refresh: If True, re-download data
|
109
|
+
|
110
|
+
Returns:
|
111
|
+
Dictionary containing Gen 8 random battle data
|
112
|
+
"""
|
113
|
+
if self._gen8_data_cache is not None and not force_refresh:
|
114
|
+
return self._gen8_data_cache
|
115
|
+
|
116
|
+
cache_file = os.path.join(self.cache_dir, "gen8_randombattle.json")
|
117
|
+
data = self._download_json_data(self.GEN8_URL, cache_file, force_refresh)
|
118
|
+
|
119
|
+
self._gen8_data_cache = data
|
120
|
+
return data
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
def get_pokemon_gen9_sets(self, pokemon_name: str, force_refresh: bool = False) -> Optional[Dict[str, Any]]:
|
125
|
+
"""
|
126
|
+
Get Generation 9 random battle sets for a specific Pokemon.
|
127
|
+
|
128
|
+
Args:
|
129
|
+
pokemon_name: Name of the Pokemon (case-insensitive)
|
130
|
+
force_refresh: If True, re-download data
|
131
|
+
|
132
|
+
Returns:
|
133
|
+
Pokemon's Gen 9 sets or None if not found
|
134
|
+
"""
|
135
|
+
data = self.get_gen9_sets(force_refresh)
|
136
|
+
return data.get(pokemon_name.lower())
|
137
|
+
|
138
|
+
def get_pokemon_gen8_data(self, pokemon_name: str, force_refresh: bool = False) -> Optional[Dict[str, Any]]:
|
139
|
+
"""
|
140
|
+
Get Generation 8 random battle data for a specific Pokemon.
|
141
|
+
|
142
|
+
Args:
|
143
|
+
pokemon_name: Name of the Pokemon (case-insensitive)
|
144
|
+
force_refresh: If True, re-download data
|
145
|
+
|
146
|
+
Returns:
|
147
|
+
Pokemon's Gen 8 data or None if not found
|
148
|
+
"""
|
149
|
+
data = self.get_gen8_data(force_refresh)
|
150
|
+
return data.get(pokemon_name.lower())
|
151
|
+
|
152
|
+
def search_pokemon_by_move(self, move_name: str, generation: int = 9, force_refresh: bool = False) -> List[str]:
|
153
|
+
"""
|
154
|
+
Search for Pokemon that have a specific move in their random battle sets.
|
155
|
+
|
156
|
+
Args:
|
157
|
+
move_name: Name of the move to search for (case-insensitive)
|
158
|
+
generation: Generation to search in (8 or 9)
|
159
|
+
force_refresh: If True, re-download data
|
160
|
+
|
161
|
+
Returns:
|
162
|
+
List of Pokemon names that have the move
|
163
|
+
"""
|
164
|
+
move_name_lower = move_name.lower()
|
165
|
+
results = []
|
166
|
+
|
167
|
+
if generation == 9:
|
168
|
+
data = self.get_gen9_sets(force_refresh)
|
169
|
+
for pokemon_name, pokemon_data in data.items():
|
170
|
+
if 'moves' in pokemon_data:
|
171
|
+
if any(move.lower() == move_name_lower for move in pokemon_data['moves']):
|
172
|
+
results.append(pokemon_name)
|
173
|
+
elif generation == 8:
|
174
|
+
data = self.get_gen8_data(force_refresh)
|
175
|
+
for pokemon_name, pokemon_data in data.items():
|
176
|
+
if 'moves' in pokemon_data:
|
177
|
+
if any(move.lower() == move_name_lower for move in pokemon_data['moves']):
|
178
|
+
results.append(pokemon_name)
|
179
|
+
|
180
|
+
return results
|
181
|
+
|
182
|
+
def search_pokemon_by_ability(self, ability_name: str, generation: int = 9, force_refresh: bool = False) -> List[str]:
|
183
|
+
"""
|
184
|
+
Search for Pokemon that have a specific ability in their random battle sets.
|
185
|
+
|
186
|
+
Args:
|
187
|
+
ability_name: Name of the ability to search for (case-insensitive)
|
188
|
+
generation: Generation to search in (8 or 9)
|
189
|
+
force_refresh: If True, re-download data
|
190
|
+
|
191
|
+
Returns:
|
192
|
+
List of Pokemon names that have the ability
|
193
|
+
"""
|
194
|
+
ability_name_lower = ability_name.lower()
|
195
|
+
results = []
|
196
|
+
|
197
|
+
if generation == 9:
|
198
|
+
data = self.get_gen9_sets(force_refresh)
|
199
|
+
for pokemon_name, pokemon_data in data.items():
|
200
|
+
if 'abilities' in pokemon_data:
|
201
|
+
if any(ability.lower() == ability_name_lower for ability in pokemon_data['abilities']):
|
202
|
+
results.append(pokemon_name)
|
203
|
+
elif generation == 8:
|
204
|
+
data = self.get_gen8_data(force_refresh)
|
205
|
+
for pokemon_name, pokemon_data in data.items():
|
206
|
+
if 'abilities' in pokemon_data:
|
207
|
+
if any(ability.lower() == ability_name_lower for ability in pokemon_data['abilities']):
|
208
|
+
results.append(pokemon_name)
|
209
|
+
|
210
|
+
return results
|
211
|
+
|
212
|
+
def get_available_generations(self) -> List[int]:
|
213
|
+
"""
|
214
|
+
Get list of available generations in the downloaded data.
|
215
|
+
|
216
|
+
Returns:
|
217
|
+
List of generation numbers
|
218
|
+
"""
|
219
|
+
return [8, 9] # Only Gen 8 and 9 are available via the API
|
220
|
+
|
221
|
+
def get_generation_formats(self, generation: int) -> List[str]:
|
222
|
+
"""
|
223
|
+
Get available formats for a specific generation.
|
224
|
+
|
225
|
+
Args:
|
226
|
+
generation: Generation number
|
227
|
+
|
228
|
+
Returns:
|
229
|
+
List of available format names
|
230
|
+
"""
|
231
|
+
if generation in [8, 9]:
|
232
|
+
return ["randombattle"] # Only random battle format is available via the API
|
233
|
+
return []
|
234
|
+
|
235
|
+
def clear_cache(self) -> None:
|
236
|
+
"""Clear all cached data."""
|
237
|
+
self._gen9_sets_cache = None
|
238
|
+
self._gen8_data_cache = None
|
239
|
+
|
240
|
+
def cleanup_downloads(self) -> None:
|
241
|
+
"""Remove downloaded cache files."""
|
242
|
+
cache_files = [
|
243
|
+
os.path.join(self.cache_dir, "gen8_randombattle.json"),
|
244
|
+
os.path.join(self.cache_dir, "gen9_randombattle.json")
|
245
|
+
]
|
246
|
+
|
247
|
+
for cache_file in cache_files:
|
248
|
+
if os.path.exists(cache_file):
|
249
|
+
os.remove(cache_file)
|
250
|
+
|
251
|
+
self.clear_cache()
|