Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- from io import BytesIO
- from sys import argv
- from textwrap import wrap
- from zipfile import ZipFile
- from fimfarchive.fetchers import FimfarchiveFetcher
- from fimfarchive.stories import Story
- from fimfarchive.utils import tqdm
- TERMS = {
- 'bone',
- 'remember',
- 'stasis',
- 'tar wol',
- }
- TAGS = {
- 'Human',
- 'Princess Luna',
- }
- def matches(story: Story) -> bool:
- tags = {tag['name'] for tag in story.meta['tags']}
- for tag in TAGS:
- if tag not in tags:
- return False
- zobj = ZipFile(BytesIO(story.data))
- html = [name for name in zobj.namelist() if name.endswith('html')]
- text = b' '.join(zobj.read(name) for name in html).decode().lower()
- for term in TERMS:
- if term not in text:
- return False
- return True
- def main(*args: str) -> None:
- if len(args) != 2:
- exit(f"Usage: {args[0]} <ARCHIVE>")
- fetcher = FimfarchiveFetcher(args[1])
- progress = tqdm(fetcher)
- for story in progress:
- if not matches(story):
- continue
- key = story.key
- meta = story.meta
- name = meta['title']
- desc = '\n'.join(wrap(meta['short_description']))
- line = f"[{key}] {name}\n{desc}\n"
- progress.write(line)
- if __name__ == '__main__':
- main(*argv)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement