mirror of
https://github.com/JockeTF/fimfarchive.git
synced 2024-11-22 05:17:59 +01:00
Use Fimfiction APIv2 in update command
This commit is contained in:
parent
72cf33fb0c
commit
22b6ed1c9c
1 changed files with 39 additions and 5 deletions
|
@ -22,15 +22,20 @@ Update command.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
from argparse import ArgumentParser, Namespace, FileType
|
from argparse import ArgumentParser, Namespace, FileType
|
||||||
|
from os.path import basename
|
||||||
from typing import Any, Iterable, Iterator, Optional
|
from typing import Any, Iterable, Iterator, Optional
|
||||||
|
|
||||||
|
import arrow
|
||||||
from jmespath import compile as jmes
|
from jmespath import compile as jmes
|
||||||
|
|
||||||
from fimfarchive.fetchers import Fetcher, FimfarchiveFetcher, FimfictionFetcher
|
from fimfarchive.fetchers import (
|
||||||
|
Fetcher, FimfarchiveFetcher, Fimfiction2Fetcher, FimfictionFetcher,
|
||||||
|
)
|
||||||
from fimfarchive.flavors import UpdateStatus
|
from fimfarchive.flavors import UpdateStatus
|
||||||
from fimfarchive.selectors import Selector, RefetchSelector
|
from fimfarchive.selectors import Selector, RefetchSelector, UpdateSelector
|
||||||
from fimfarchive.signals import SignalReceiver
|
from fimfarchive.signals import SignalReceiver
|
||||||
from fimfarchive.stories import Story
|
from fimfarchive.stories import Story
|
||||||
from fimfarchive.tasks import UpdateTask
|
from fimfarchive.tasks import UpdateTask
|
||||||
|
@ -43,6 +48,9 @@ __all__ = (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
ACCESS_TOKEN_KEY = 'FIMFICTION_ACCESS_TOKEN'
|
||||||
|
|
||||||
|
|
||||||
class StoryFormatter(Iterable[str]):
|
class StoryFormatter(Iterable[str]):
|
||||||
"""
|
"""
|
||||||
Generates a text representation of story meta.
|
Generates a text representation of story meta.
|
||||||
|
@ -199,6 +207,12 @@ class UpdateCommand(Command):
|
||||||
description=self.__doc__,
|
description=self.__doc__,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'--alpha',
|
||||||
|
help="fetch from Fimfiction APIv1",
|
||||||
|
action='store_true',
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--archive',
|
'--archive',
|
||||||
help="previous version of the archive",
|
help="previous version of the archive",
|
||||||
|
@ -222,12 +236,30 @@ class UpdateCommand(Command):
|
||||||
Args:
|
Args:
|
||||||
opts: Parsed command line arguments.
|
opts: Parsed command line arguments.
|
||||||
"""
|
"""
|
||||||
fimfarchive: Fetcher = FimfarchiveFetcher(opts.archive)
|
fimfarchive: Fetcher
|
||||||
fimfiction: Fetcher = FimfictionFetcher()
|
fimfiction: Fetcher
|
||||||
selector: Optional[Selector] = None
|
selector: Selector
|
||||||
|
|
||||||
|
token = os.environ.get(ACCESS_TOKEN_KEY)
|
||||||
|
|
||||||
|
if opts.alpha:
|
||||||
|
fimfiction = FimfictionFetcher()
|
||||||
|
elif token:
|
||||||
|
fimfiction = Fimfiction2Fetcher(token, True, opts.refetch)
|
||||||
|
else:
|
||||||
|
exit(f"Environment variable required: {ACCESS_TOKEN_KEY}")
|
||||||
|
|
||||||
if opts.refetch:
|
if opts.refetch:
|
||||||
selector = RefetchSelector()
|
selector = RefetchSelector()
|
||||||
|
else:
|
||||||
|
selector = UpdateSelector()
|
||||||
|
|
||||||
|
print(f"\nStarted: {arrow.now()}")
|
||||||
|
print(f"Archive: {basename(opts.archive.name)}")
|
||||||
|
print(f"Fetcher: {type(fimfiction).__name__}")
|
||||||
|
print(f"Selector: {type(selector).__name__}")
|
||||||
|
|
||||||
|
fimfarchive = FimfarchiveFetcher(opts.archive)
|
||||||
|
|
||||||
return UpdateTask(
|
return UpdateTask(
|
||||||
fimfarchive=fimfarchive,
|
fimfarchive=fimfarchive,
|
||||||
|
@ -242,4 +274,6 @@ class UpdateCommand(Command):
|
||||||
with UpdatePrinter(task):
|
with UpdatePrinter(task):
|
||||||
task.run()
|
task.run()
|
||||||
|
|
||||||
|
print(f"\nDone: {arrow.now()}")
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Reference in a new issue