Split out config file handling into its own function
This commit is contained in:
parent
8229a14cfe
commit
a1a6998e52
1 changed files with 26 additions and 13 deletions
39
discorss.py
39
discorss.py
|
@ -56,30 +56,43 @@ def get_description(feed):
|
||||||
return desc
|
return desc
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def setupPaths():
|
||||||
os.environ["TZ"] = "America/Toronto"
|
global app_config
|
||||||
time.tzset()
|
|
||||||
# Check for log and config files/paths, create empty directories if needed
|
# Check for log and config files/paths, create empty directories if needed
|
||||||
# TODO: make this cleaner
|
# TODO: make this cleaner
|
||||||
try:
|
if not Path(log_file_path).exists():
|
||||||
Path(log_file_path).mkdir(parents=True, exist_ok=True)
|
print("No log file path exists. Yark! We'll try and make {}...", log_dir)
|
||||||
except FileExistsError:
|
try:
|
||||||
print(
|
Path(log_dir).mkdir(parents=True, exist_ok=True)
|
||||||
"The logfile path {} already exists and is not a directory!".format(
|
except FileExistsError:
|
||||||
log_file_path
|
print("The path {} already exists and is not a directory!".format(log_dir))
|
||||||
)
|
|
||||||
)
|
|
||||||
if not Path(config_file_path).exists():
|
if not Path(config_file_path).exists():
|
||||||
print(
|
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
|
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
|
return
|
||||||
|
# Loading the config file
|
||||||
with open(config_file_path, "r") as config_file:
|
with open(config_file_path, "r") as config_file:
|
||||||
app_config = json.load(config_file)
|
app_config = json.load(config_file)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
os.environ["TZ"] = "America/Toronto"
|
||||||
|
time.tzset()
|
||||||
now = time.mktime(time.localtime())
|
now = time.mktime(time.localtime())
|
||||||
|
setupPaths() # Handle the config and log paths
|
||||||
try:
|
try:
|
||||||
last_check = app_config["lastupdate"]
|
last_check = app_config["lastupdate"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
Loading…
Add table
Reference in a new issue