mirror of
https://github.com/phin05/discord-rich-presence-plex
synced 2024-11-22 01:23:02 +00:00
41 lines
1 KiB
Python
41 lines
1 KiB
Python
|
from models.config import Config
|
||
|
from store.constants import configFilePath
|
||
|
from utils.logging import logger
|
||
|
from utils.dict import merge
|
||
|
import json
|
||
|
import os
|
||
|
import time
|
||
|
|
||
|
config: Config = {
|
||
|
"logging": {
|
||
|
"debug": True,
|
||
|
},
|
||
|
"display": {
|
||
|
"useRemainingTime": False,
|
||
|
"posters": {
|
||
|
"enabled": False,
|
||
|
"imgurClientID": "",
|
||
|
},
|
||
|
},
|
||
|
"users": [],
|
||
|
}
|
||
|
|
||
|
def loadConfig() -> None:
|
||
|
if os.path.isfile(configFilePath):
|
||
|
try:
|
||
|
with open(configFilePath, "r", encoding = "UTF-8") as configFile:
|
||
|
loadedConfig = json.load(configFile)
|
||
|
merge(loadedConfig, config)
|
||
|
except:
|
||
|
os.rename(configFilePath, configFilePath.replace(".json", f"-{time.time():.0f}.json"))
|
||
|
logger.exception("Failed to parse the application's config file. A new one will be created.")
|
||
|
saveConfig()
|
||
|
|
||
|
def saveConfig() -> None:
|
||
|
try:
|
||
|
with open(configFilePath, "w", encoding = "UTF-8") as configFile:
|
||
|
json.dump(config, configFile, indent = "\t")
|
||
|
configFile.write("\n")
|
||
|
except:
|
||
|
logger.exception("Failed to write to the application's config file.")
|