handle cfg defaults better

This commit is contained in:
Lynne 2019-04-29 13:59:37 +10:00
parent 48faf4d3b3
commit 99d1d13fbf
No known key found for this signature in database
GPG Key ID: FB7B970303ACE499
1 changed files with 10 additions and 16 deletions

26
main.py
View File

@ -12,25 +12,19 @@ import requests
import functions import functions
scopes = ["read:statuses", "read:accounts", "read:follows", "write:statuses", "read:notifications"] scopes = ["read:statuses", "read:accounts", "read:follows", "write:statuses", "read:notifications"]
#cfg defaults
cfg = {
"site": "https://botsin.space",
"cw": None,
"instance_blacklist": ["bofa.lol", "witches.town"],
"learn_from_cw": False
}
try: try:
cfg = json.load(open('config.json', 'r')) cfg.update(json.load(open('config.json', 'r')))
except: except:
shutil.copy2("config.sample.json", "config.json")
cfg = json.load(open('config.json', 'r'))
#config.json should contain the instance URL, the instance blacklist (for dead/broken instances), and the CW text. if they're not provided, we'll fall back to defaults. shutil.copy2("config.sample.json", "config.json")
# TODO: this is pretty messy cfg.update(json.load(open('config.json', 'r')))
if 'site' not in cfg:
cfg['website'] = "https://botsin.space"
if 'cw' not in cfg:
cfg['cw'] = None
if 'instance_blacklist' not in cfg:
cfg["instance_blacklist"] = [
"bofa.lol",
"witches.town"
]
if 'learn_from_cw' not in cfg:
cfg['learn_from_cw'] = False
#if the user is using a (very!) old version that still uses the .secret files, migrate to the new method #if the user is using a (very!) old version that still uses the .secret files, migrate to the new method
if os.path.exists("clientcred.secret"): if os.path.exists("clientcred.secret"):