diff --git a/fimfarchive/commands/__init__.py b/fimfarchive/commands/__init__.py index 00ccc3c..9bc0286 100644 --- a/fimfarchive/commands/__init__.py +++ b/fimfarchive/commands/__init__.py @@ -24,11 +24,13 @@ Command module. from .base import Command from .root import RootCommand +from .normal import NormalCommand from .update import UpdateCommand __all__ = ( 'Command', 'RootCommand', + 'NormalCommand', 'UpdateCommand', ) diff --git a/fimfarchive/commands/normal.py b/fimfarchive/commands/normal.py new file mode 100644 index 0000000..767b5b7 --- /dev/null +++ b/fimfarchive/commands/normal.py @@ -0,0 +1,55 @@ +""" +Normalize command. +""" + + +# +# Fimfarchive, preserves stories from Fimfiction. +# Copyright (C) 2019 Joakim Soderlund +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + + +from pathlib import Path + +from fimfarchive.converters import LocalUtcConverter +from fimfarchive.fetchers import DirectoryFetcher +from fimfarchive.utils import tqdm +from fimfarchive.writers import DirectoryWriter + + +from .base import Command + + +__all__ = ( + 'NormalCommand', +) + + +class NormalCommand(Command): + """ + Normalizes updated story meta. + """ + + def __call__(self, *args: str) -> int: + convert = LocalUtcConverter() + fetcher = DirectoryFetcher(meta_path=Path('worktree/update/meta')) + writer = DirectoryWriter(meta_path='worktree/normal/meta') + + for story in tqdm(fetcher): + story = convert(story) + writer.write(story) + + return 0 diff --git a/fimfarchive/commands/root.py b/fimfarchive/commands/root.py index b5adcc9..02e5c8b 100644 --- a/fimfarchive/commands/root.py +++ b/fimfarchive/commands/root.py @@ -25,6 +25,7 @@ Root command. from typing import Dict, Type from .base import Command +from .normal import NormalCommand from .update import UpdateCommand @@ -38,6 +39,7 @@ class RootCommand(Command): The main application command. """ commands: Dict[str, Type[Command]] = { + 'normal': NormalCommand, 'update': UpdateCommand, }