localdex 0.1.20__py3-none-any.whl → 0.1.22__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 +0 -4
- localdex/core.py +2 -185
- localdex/data/pokemon/aegislash.json +88 -0
- localdex/data/pokemon/basculegion.json +86 -0
- localdex/data/pokemon/basculin.json +105 -0
- localdex/data/pokemon/darmanitan.json +117 -0
- localdex/data/pokemon/deoxys.json +144 -0
- localdex/data/pokemon/dudunsparce.json +117 -0
- localdex/data/pokemon/eiscue.json +80 -0
- localdex/data/pokemon/enamorus.json +77 -0
- localdex/data/pokemon/giratina.json +123 -0
- localdex/data/pokemon/gourgeist.json +109 -0
- localdex/data/pokemon/indeedee.json +89 -0
- localdex/data/pokemon/keldeo.json +107 -0
- localdex/data/pokemon/landorus.json +105 -0
- localdex/data/pokemon/lycanroc.json +107 -0
- localdex/data/pokemon/maushold.json +80 -0
- localdex/data/pokemon/meloetta.json +131 -0
- localdex/data/pokemon/meowstic.json +122 -0
- localdex/data/pokemon/mimikyu.json +113 -0
- localdex/data/pokemon/minior.json +90 -0
- localdex/data/pokemon/morpeko.json +100 -0
- localdex/data/pokemon/nidoran.json +109 -0
- localdex/data/pokemon/oinkologne.json +78 -0
- localdex/data/pokemon/oricorio.json +91 -0
- localdex/data/pokemon/palafin.json +90 -0
- localdex/data/pokemon/pumpkaboo.json +105 -0
- localdex/data/pokemon/shaymin.json +101 -0
- localdex/data/pokemon/squawkabilly.json +79 -0
- localdex/data/pokemon/tatsugiri.json +65 -0
- localdex/data/pokemon/thundurus.json +116 -0
- localdex/data/pokemon/tornadus.json +107 -0
- localdex/data/pokemon/toxtricity.json +112 -0
- localdex/data/pokemon/urshifu.json +101 -0
- localdex/data/pokemon/wishiwashi.json +77 -0
- localdex/data/pokemon/wormadam.json +93 -0
- localdex/data/pokemon/zygarde.json +93 -0
- localdex/download_data.py +62 -0
- localdex/models/pokemon.py +8 -11
- {localdex-0.1.20.dist-info → localdex-0.1.22.dist-info}/METADATA +2 -171
- {localdex-0.1.20.dist-info → localdex-0.1.22.dist-info}/RECORD +44 -11
- localdex/random_battles.py +0 -251
- localdex/sprite_downloader.py +0 -932
- {localdex-0.1.20.dist-info → localdex-0.1.22.dist-info}/WHEEL +0 -0
- {localdex-0.1.20.dist-info → localdex-0.1.22.dist-info}/entry_points.txt +0 -0
- {localdex-0.1.20.dist-info → localdex-0.1.22.dist-info}/top_level.txt +0 -0
localdex/random_battles.py
DELETED
@@ -1,251 +0,0 @@
|
|
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()
|