Skip to content

Commit

Permalink
Add command for counting release changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JockeTF committed Aug 30, 2020
1 parent f771c3e commit bdbed16
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fimfarchive/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from .base import Command
from .build import BuildCommand
from .count import CountCommand
from .root import RootCommand
from .update import UpdateCommand

Expand All @@ -32,5 +33,6 @@
'Command',
'RootCommand',
'BuildCommand',
'CountCommand',
'UpdateCommand',
)
120 changes: 120 additions & 0 deletions fimfarchive/commands/count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
"""
Count 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 <http://www.gnu.org/licenses/>.
#


from typing import Set

from fimfarchive.exceptions import InvalidStoryError
from fimfarchive.fetchers import DirectoryFetcher, FimfarchiveFetcher
from fimfarchive.stories import Story
from fimfarchive.utils import tqdm

from .base import Command


__all__ = (
'CountCommand',
)


AUTHOR_BLACKLIST: Set[int] = {
135140,
}


class CountCommand(Command):
"Mwap!"

def include(self, story: Story) -> bool:
author = int(story.meta['author']['id'])
return author not in AUTHOR_BLACKLIST

def __call__(self, *args):
fimfarchive = FimfarchiveFetcher(
source='fimfarchive.zip'
)

directory = DirectoryFetcher(
meta_path='worktree/update/meta',
data_path='worktree/render/epub',
)

previous: Set[int] = set(fimfarchive.index.keys())
upcoming: Set[int] = set()

blocked: Set[int] = set()
created: Set[int] = set()
deleted: Set[int] = set()
revived: Set[int] = set()
updated: Set[int] = set()
uniform: Set[int] = set()

for new in tqdm(directory):
key = new.key

if key != new.meta['id']:
raise ValueError("Derpy ID.")

if not self.include(new):
blocked.add(key)
continue

upcoming.add(key)

if key not in previous:
created.add(key)
continue

try:
new.data
except InvalidStoryError:
revived.add(key)
continue

old = fimfarchive.fetch(key)

if key != old.meta['id']:
raise ValueError("Derpy ID.")

if old.data != new.data:
updated.add(key)
continue

uniform.add(key)

deleted = previous - upcoming

info = [
f"Previous: {len(previous)}",
f"Upcoming: {len(upcoming)}",
f"Created: {len(created)}",
f"Revived: {len(revived)}",
f"Updated: {len(updated)}",
f"Deleted: {len(deleted)}",
f"Blocked: {len(blocked)}",
f"Uniform: {len(uniform)}",
]

print('\n'.join(info))

return 0
2 changes: 2 additions & 0 deletions fimfarchive/commands/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from .base import Command
from .build import BuildCommand
from .count import CountCommand
from .update import UpdateCommand


Expand All @@ -40,6 +41,7 @@ class RootCommand(Command):
"""
commands: Dict[str, Type[Command]] = {
'build': BuildCommand,
'count': CountCommand,
'update': UpdateCommand,
}

Expand Down

0 comments on commit bdbed16

Please sign in to comment.