Skip to content
This repository was archived by the owner on Aug 16, 2023. It is now read-only.

Commit 0b5e392

Browse files
committed
feat: download animated sprites
1 parent 2785f62 commit 0b5e392

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

.env

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
NO_ICONS=False
2+
NO_ANIMATED_SPRITES=False
23
NO_MAP_IMAGES=False
34
IGNORE_MVP_WITH_EMPTY_MAPS=False
45
USE_FILTER=False

mvp_scraper/extractor.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ def get_map_img(map_name: str, mvp_id: str, output_path: Path) -> None:
4141
)
4242

4343

44+
def get_animated_sprite(mvp_id: str, output_path: Path) -> None:
45+
download_img(
46+
output_path.joinpath('mvps_icons_animated', f'{mvp_id}.png'),
47+
f'https://db.irowiki.org/image/monster/{mvp_id}.png',
48+
f'[{mvp_id}] Animated sprite already exists, skipping...',
49+
f'[{mvp_id}] Downloading animated mvp icon {mvp_id}.png',
50+
f'[{mvp_id}] Completed download animated mvp icon {mvp_id}.png',
51+
f'[{mvp_id}] Failed to download animated mvp icon {mvp_id}.png',
52+
)
53+
54+
4455
def get_mvps_id() -> list[str]:
4556
print('Fetching mvps ids from divine pride...')
4657
ids = []
@@ -92,6 +103,7 @@ class Extractor:
92103
def __init__(self,
93104
use_filter: bool = False,
94105
no_icons: bool = False,
106+
no_animated_sprites: bool = False,
95107
no_map_images: bool = False,
96108
ignore_mvp_with_empty_maps: bool = False,
97109
desired_stats: Optional[list[str]] = None,
@@ -101,6 +113,7 @@ def __init__(self,
101113
) -> None:
102114
self.use_filter = use_filter
103115
self.no_icons = no_icons
116+
self.no_animated_sprites = no_animated_sprites
104117
self.no_map_images = no_map_images
105118
self.ignore_mvp_with_empty_maps = ignore_mvp_with_empty_maps
106119
self.desired_stats = desired_stats
@@ -132,6 +145,9 @@ def get_mvp_data(self, mvp_id: str) -> Optional[dict]:
132145
if not self.no_icons:
133146
get_mvp_icon(mvp_id.rstrip('\n'), self.output_path)
134147

148+
if not self.no_animated_sprites:
149+
get_animated_sprite(mvp_id.rstrip('\n'), self.output_path)
150+
135151
if not self.no_map_images:
136152
for map_item in mvp_info['spawn']:
137153
get_map_img(map_item['mapname'], mvp_id, self.output_path)
@@ -142,11 +158,15 @@ def extract(self) -> None:
142158
try:
143159
print(f'MVPs will {"not " if not self.use_filter else ""}be filtered.')
144160
print(f'MVPs Icons will {"not " if self.no_icons else ""}be downloaded.')
161+
print(f'MVPs Animated Sprites will {"not " if self.no_animated_sprites else ""}be downloaded.')
145162
print(f'MVPs Maps will {"not " if self.no_map_images else ""}be downloaded.')
146163

147164
if not self.no_icons and not self.output_path.joinpath('mvps_icons').exists():
148165
Path.mkdir(self.output_path.joinpath('mvps_icons'), parents=True, exist_ok=True)
149166

167+
if not self.no_animated_sprites and not self.output_path.joinpath('mvps_icons_animated').exists():
168+
Path.mkdir(self.output_path.joinpath('mvps_icons_animated'), parents=True, exist_ok=True)
169+
150170
if not self.no_map_images and not self.output_path.joinpath('maps').exists():
151171
Path.mkdir(self.output_path.joinpath('maps'), parents=True, exist_ok=True)
152172

@@ -169,7 +189,7 @@ def extract(self) -> None:
169189
except KeyboardInterrupt:
170190
print('Aborting...')
171191
except Exception as e:
172-
# print(f'{e} | {e.__class__.__name__}')
192+
print(f'{e} | {e.__class__.__name__}')
173193
exit()
174194

175195

@@ -182,13 +202,15 @@ def start() -> None:
182202
return print('Divine pride api not found, aborting...')
183203

184204
no_icons = env.bool('NO_ICONS', False)
205+
no_animated_sprites = env.bool('NO_ANIMATED_SPRITES', False)
185206
no_map_images = env.bool('NO_MAP_IMAGES', False)
186207
ignore_mvp_with_empty_maps = env.bool('IGNORE_MVP_WITH_EMPTY_MAPS', False)
187208
use_filter = env.bool('USE_FILTER', False)
188209
desired_stats = env.list('DESIRED_STATS', None)
189210
output_path = get_output_path()
190211

191-
extractor = Extractor(use_filter, no_icons, no_map_images, ignore_mvp_with_empty_maps, desired_stats,
212+
extractor = Extractor(use_filter, no_icons, no_animated_sprites, no_map_images,
213+
ignore_mvp_with_empty_maps, desired_stats,
192214
divine_pride_api_key,
193215
output_path=output_path)
194216
extractor.extract()

0 commit comments

Comments
 (0)