From 3c1afc7b73b05430905d81e5235341022fa7e8b9 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Tue, 29 Mar 2022 15:11:01 -0400 Subject: [PATCH] Take config file as command line argument --- octoprint_reservations/main.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/octoprint_reservations/main.py b/octoprint_reservations/main.py index a397e6e..70f2cce 100755 --- a/octoprint_reservations/main.py +++ b/octoprint_reservations/main.py @@ -1,6 +1,8 @@ #!/usr/bin/env python3 +import argparse from datetime import datetime, timedelta +import pathlib from octorest import OctoRest from ruamel.yaml import YAML @@ -37,10 +39,19 @@ def get_printer_job(calendar, printer): def main(): + parser = argparse.ArgumentParser(description="Process some integers.") + parser.add_argument( + "--config", + type=pathlib.Path, + default="printers.yaml", + help="A yaml file defining printers to query (default: %(default)s)", + ) + args = parser.parse_args() + calendar = CalendarService() yaml = YAML(typ="safe") - with open("printers.yaml") as f: + with open(args.config) as f: printers = yaml.load(f) for printer in printers: