Module: cli

The CLI provides command-line access to Mastoscore functionality. For a web-based interface, see Backstage. This is largely obviated by the backstage graphical interface. The reason I broke it into modules was to carefully, step-by-step go through the process. The web GUI does that now.

Subcommands

Usage

mastoscore CONFIG_FILE ACTION

Arguments:

Debugging

To activate debugging, set a debug option in the INI file.

Code Reference

cli.py: Command line module for calling mastoscore to do its work

main()

Parse command line arguments, figure out what we're doing. Do it.

Source code in mastoscore/cli.py
def main():
    """
    Parse command line arguments, figure out what we're doing. Do it.
    """
    args = None
    logger = None
    valid_actions = [
        "fetch",
        "analyse",
        "post",
        "graph",
        "wordcloud",
    ]
    parser = argparse.ArgumentParser(
        description="Fetch recent toots on a hashtag, score them. Optionally post the analysis"
    )
    parser.add_argument(
        "config",
        type=str,
        help="INI config file with config plus credentials.",
    )
    parser.add_argument(
        "action",
        type=str,
        default=None,
        help="Action to take: fetch, analyse, post, graph, wordcloud.",
    )
    args = parser.parse_args()

    try:
        config = read_config(args.config)
        if config is None:
            exit(2)
    except FileNotFoundError:
        logging.error(f"Config file not found: {args.config}")
        exit(2)
    except PermissionError:
        logging.error(f"Permission denied reading config file: {args.config}")
        exit(2)
    except Exception as e:
        logging.error(f"Error reading config file: {e}")
        exit(2)

    # Set up logging based on config
    logger = get_logger(config, __name__)
    logger.debug("Logging activated")

    match args.action:
        case "blog":
            blog(config)
        case "fetch":
            fetch(config)
        case "analyse":
            analyse(config)
        case "post":
            post(config)
        case "graph":
            graph(config)
        case "graphs":
            graph(config)
            write_wordcloud(config)
        case "wordcloud":
            write_wordcloud(config)
        case _:
            parser.print_help()
            logger.error(
                f"'{args.action}' is not a valid action. Must be one of: {valid_actions}"
            )
            exit(1)
    exit(0)