added support for keys in external files

This commit is contained in:
2023-08-01 21:58:56 +02:00
parent db71bf8452
commit 12a4ab7ae7
3 changed files with 29 additions and 2 deletions

View File

@ -1,11 +1,21 @@
import requests, json, re
import requests, json, re, os
from datetime import datetime
def loadSettings() -> dict:
# TODO: check integrity
try:
with open('config.json', 'r') as file:
return json.load(file)
# Read if the API keys are path to files
config = json.load(file)
keys = config['api'].keys()
mask = dict()
for key in keys:
api_key = key
if os.path.exists(key):
with open(key, 'r') as file:
api_key = file.readline().strip()
mask[key] = api_key
config['api'] = { mask[key]: value for key, value in config['api'].items() }
except FileNotFoundError:
sample_config = {
'api': {},