diff --git a/requirements.txt b/requirements.txt index 94d93df..01b3c99 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,7 @@ Flask requests SuperJson Toolz +requests +SuperJson +Toolz +typed-argument-parser \ No newline at end of file diff --git a/src/archive_chan/params.py b/src/archive_chan/params.py index f84340c..d0b80ba 100644 --- a/src/archive_chan/params.py +++ b/src/archive_chan/params.py @@ -1,70 +1,20 @@ -from argparse import ArgumentParser +from tap import Tap from pathlib import Path +class Args(Tap): + thread: str # Link to the 4chan thread or the name of the board. + archived: bool = False # Download threads from the /board/archive/ as well. + archived_only: bool = False # Download threads from the /board/archive/ INSTEAD. + preserve_media: bool = False # Save images and video files locally. + path: Path = Path("./threads/") # Path to folder where the threads should be saved. + posts: int = None # Number of posts to download. + retries: int = 1 # Retry -r times if a download fails. + skip_renders: bool = False # Do not render thread HTMLs after downloading them. + text_only: bool = False # Download only HTMLs or JSONs. + use_db: bool = False # Stores threads into a database, this is experimental. + verbose: bool = False # Verbose logging to stdout. def get_args(): """Get user input from the command-line and parse it.""" - parser = ArgumentParser(description="Archives 4chan threads") - parser.add_argument( - "thread", help="Link to the 4chan thread or the name of the board." - ) - parser.add_argument( - "-a", - "--archived", - action="store_true", - help="Download threads from the /board/archive/ as well.", - ) - parser.add_argument( - "-ao", - "--archived_only", - action="store_true", - help="Download threads from the /board/archive/ INSTEAD.", - ) - parser.add_argument( - "-p", - "--preserve_media", - action="store_true", - help="Save images and video files locally.", - ) - parser.add_argument( - "--path", - default="./threads/", - help="Path to folder where the threads should be saved.", - type=Path, - ) - parser.add_argument( - "--posts", - default=None, - help="Number of posts to download", - type=int, - ) - parser.add_argument( - "-r", - "--retries", - default=1, - help="Retry -r times if a download fails.", - type=int, - ) - parser.add_argument( - "--skip_renders", - action="store_true", - help="Do not render thread HTMLs after downloading them.", - ) - parser.add_argument( - "--text_only", - action="store_true", - help="Download only HTMLs or JSONs.", - ) - parser.add_argument( - "--use_db", - action="store_true", - help="Stores threads into a database, this is experimental.", - ) - parser.add_argument( - "-v", - "--verbose", - action="store_true", - help="Verbose logging to stdout.", - ) - args = parser.parse_args() - return args + args = Args().parse_args() + return args \ No newline at end of file