Checks config; other changes

This commit is contained in:
localhost_frssoft 2022-11-10 02:23:18 +03:00
parent 097051cdef
commit fba68e7a70
4 changed files with 37 additions and 66 deletions

View file

@ -1,7 +1,10 @@
import json, requests, time
from os.path import exists
from loguru import logger
defaut_conf = {
conf_file = 'config.json'
default_conf = {
'instance': 'fw.ponychord.rocks',
'public_list_instances': [
"open.audio",
@ -35,6 +38,33 @@ defaut_conf = {
}
def set_defaults(corrected_config=None):
conf_rewrite = default_conf
if corrected_config:
conf_rewrite = corrected_config
with open(conf_file, 'wt') as f:
f.write(json.dumps(conf_rewrite, indent=4))
def check_config():
'''Check config and remove keys if not found in default config'''
with open(conf_file, 'rt') as f:
loaded_config = json.loads(f.read())
correct_conf = {}
for k, v in loaded_config.items():
if k in default_conf.keys():
correct_conf[k] = v
else:
logger.warning(f'{k} from config will be removed. Value: {v}')
set_defaults(correct_conf)
if not exists(conf_file):
set_defaults()
else:
check_config()
@logger.catch
def get_new_funkwhale_servers():
# Uses official API network.funkwhale.audio for getting new instances