Skip to content

Commit

Permalink
Add typed-argument-parser to requirements.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
AutoPR committed May 2, 2023
1 parent 7a647af commit 491db4f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 65 deletions.
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ Flask
requests
SuperJson
Toolz
requests
SuperJson
Toolz
typed-argument-parser
80 changes: 15 additions & 65 deletions src/archive_chan/params.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 491db4f

Please sign in to comment.