mirror of
https://github.com/JockeTF/fimfarchive.git
synced 2024-11-22 05:17:59 +01:00
Make FimfarchiveFetcher iterable
This commit is contained in:
parent
cb58cfaa53
commit
b916699127
1 changed files with 14 additions and 0 deletions
|
@ -31,6 +31,7 @@ from jmespath import compile as jmes
|
|||
|
||||
from fimfarchive.exceptions import InvalidStoryError, StorySourceError
|
||||
from fimfarchive.flavors import StorySource, DataFormat, MetaPurity
|
||||
from fimfarchive.stories import Story
|
||||
from fimfarchive.utils import Empty
|
||||
|
||||
from .base import Fetcher
|
||||
|
@ -140,6 +141,19 @@ class FimfarchiveFetcher(Fetcher):
|
|||
except ValueError as e:
|
||||
raise StorySourceError(f"Malformed index key: {key}") from e
|
||||
|
||||
def __len__(self) -> int:
|
||||
"""
|
||||
Returns the total number of stories in the archive.
|
||||
"""
|
||||
return len(self.index)
|
||||
|
||||
def __iter__(self) -> Iterable[Story]:
|
||||
"""
|
||||
Yields all stories in the archive, ordered by ID.
|
||||
"""
|
||||
for key in sorted(self.index.keys()):
|
||||
yield self.fetch(key)
|
||||
|
||||
def validate(self, key: int) -> int:
|
||||
"""
|
||||
Ensures that the key matches a valid story
|
||||
|
|
Loading…
Reference in a new issue