diff --git a/discorss.py b/discorss.py index 83c71bd..f0ee41f 100755 --- a/discorss.py +++ b/discorss.py @@ -56,30 +56,43 @@ def get_description(feed): return desc -def main(): - os.environ["TZ"] = "America/Toronto" - time.tzset() +def setupPaths(): + global app_config # Check for log and config files/paths, create empty directories if needed # TODO: make this cleaner - try: - Path(log_file_path).mkdir(parents=True, exist_ok=True) - except FileExistsError: - print( - "The logfile path {} already exists and is not a directory!".format( - log_file_path - ) - ) + if not Path(log_file_path).exists(): + print("No log file path exists. Yark! We'll try and make {}...", log_dir) + try: + Path(log_dir).mkdir(parents=True, exist_ok=True) + except FileExistsError: + print("The path {} already exists and is not a directory!".format(log_dir)) if not Path(config_file_path).exists(): print( - "No config file at {}! Snarf.\n{} was created for you.".format( + "No config file at {}! Snarf. We'll try and make {}...".format( config_file_path, config_dir ) ) - Path(config_dir).mkdir(parents=True, exist_ok=True) + try: + Path(config_dir).mkdir(parents=True, exist_ok=True) + except FileExistsError: + print( + "The config dir {} already exists and is not a directory! Please fix manually.".format( + config_dir + ) + ) + sys.exit(255) return + # Loading the config file with open(config_file_path, "r") as config_file: app_config = json.load(config_file) + return + + +def main(): + os.environ["TZ"] = "America/Toronto" + time.tzset() now = time.mktime(time.localtime()) + setupPaths() # Handle the config and log paths try: last_check = app_config["lastupdate"] except KeyError: