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¶
fetch: Connect to servers and fetch tootsanalyse: Read fetched files and analyse them, storing results in JSONgraph: Draw a histogram of activity during the eventwordcloud: Draw a word cloud of words used during the eventgraphs: Convenience command that runs bothgraphandwordcloudblog: Create a markdown blog post.post: Read analysis files and post results and graphs to Mastodon
Usage¶
mastoscore CONFIG_FILE ACTION
Arguments:
CONFIG_FILE- Path to .ini configuration file (required)ACTION- One of: fetch, analyse, post, graph, wordcloud, graphs
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)