diff --git a/remindme_caldav.py b/remindme_caldav.py index c0ea9b1..5303c97 100644 --- a/remindme_caldav.py +++ b/remindme_caldav.py @@ -14,15 +14,15 @@ from alert_processor import AlertProcessor logger = logging.getLogger() -def setup_logging(): +def setup_logging(logfile = "log"): log_format='[%(levelname)s] %(asctime)s %(message)s' - logging.basicConfig(format=log_format, level=logging.INFO) + logging.basicConfig(filename = logfile, format=log_format, level=logging.INFO) def parse_args(): """Parse command line arguments.""" parser = argparse.ArgumentParser(description="A simple calendar alerting daemon written in Python") parser.add_argument('--config', type=str, help='Path to config file. Must be .toml') - parser.add_argument('--logfile', type=str, help='Path to logfile file. Default logfile', default = "none") + parser.add_argument('--logfile', type=str, help='Path to logfile file. Defaults to "log" in current directory.', default = "log") parser.add_argument('--loglevel', help="Set the log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)", type=str, choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']) return parser.parse_args() @@ -340,12 +340,12 @@ def process_alert(current_time, next_alert, next_event, event, config): return def main(): - setup_logging() - logger = logging.getLogger() # Assign a default value to logger - # Parse args args = parse_args() + setup_logging(args.logfile) + logger = logging.getLogger() # Assign a default value to logger + # Set log level if args.loglevel is not None: numeric_level = getattr(logging, args.loglevel.upper(), None) # Convert string to integer @@ -370,12 +370,15 @@ def main(): sys.exit(1) # Parse calendar events - calendar_parser = CalendarParser() - files = list(cal_dir.glob('*.ics')) - if len(files) == 0: - logger.error("No calendar files in destination location. Did you sync with the caldav server?") - sys.exit(1) + no_files_detected = True + logger.info(f"Looking for calendar files in {cal_dir}...") + while no_files_detected is True: + files = list(cal_dir.glob('*.ics')) + if len(files) != 0: + logger.info("Calendar files detected in sync location!") + no_files_detected = False + calendar_parser = CalendarParser() event_list = [] for file in files: with open(file, 'r') as f: