* pull - will download thumbnails and update the database * serve - (in the future) will run an HTTP frontend server to display the pulled data Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
import asyncio
|
|
import argparse
|
|
|
|
from .pull import pull
|
|
|
|
|
|
def parse_args():
|
|
parser = argparse.ArgumentParser(description="Run 4chan bans archiver")
|
|
subparsers = parser.add_subparsers(title="Commands", dest="command")
|
|
|
|
subcommands = set()
|
|
|
|
def add_subcommand(subcommand: str, *args, **kwargs):
|
|
nonlocal subparsers, subcommands
|
|
assert (
|
|
subcommand not in subcommands
|
|
), f"subcommand {subcommand} was already registered"
|
|
subcommands |= {subcommand}
|
|
return subparsers.add_parser(subcommand, *args, **kwargs)
|
|
|
|
_pull_parser = add_subcommand(
|
|
"pull",
|
|
help="Pull bans from 4chan, save thumbnails, update the database, and exit",
|
|
)
|
|
_serve_parser = add_subcommand("serve", help="Start HTTP server")
|
|
_help_parser = add_subcommand("help", help="Show this help message")
|
|
|
|
args = parser.parse_args()
|
|
|
|
if args.command not in subcommands or args.command == "help":
|
|
parser.print_help()
|
|
|
|
return args
|
|
|
|
|
|
async def main():
|
|
args = parse_args()
|
|
match args.command:
|
|
case "pull":
|
|
await pull()
|
|
case "serve":
|
|
print("TODO: HTTP server")
|
|
case command:
|
|
assert False, f"unknown command {command} that was not caught in add_subcommand"
|
|
|
|
asyncio.run(main())
|