feat: Make the storage directory configurable
This commit is contained in:
@@ -73,8 +73,11 @@ class WarningBot:
|
||||
self._client = None
|
||||
self._refresh_timeout = 630 # 15min
|
||||
|
||||
# Configuration stuff
|
||||
self._data_dir = ''
|
||||
|
||||
self._load_config()
|
||||
|
||||
|
||||
async def connect(self):
|
||||
'''
|
||||
Starts the "event loop" of the bot
|
||||
@@ -85,19 +88,20 @@ class WarningBot:
|
||||
|
||||
# First we check if the entered Landkreis is valid
|
||||
channels = {}
|
||||
if not os.path.exists('/etc/janine/channels.json'):
|
||||
channel_file = os.path.join(self._data_dir, 'channels.json')
|
||||
if not os.path.exists(channel_file):
|
||||
log.debug('Requesting search channels')
|
||||
req = requests.get(MiscDataSources.channels())
|
||||
channels = json.loads(req.text)
|
||||
|
||||
try:
|
||||
with open('/etc/janine/channels.json', 'w') as f:
|
||||
with open(channel_file, 'w') as f:
|
||||
f.write(json.dumps(channels))
|
||||
except Exception as err:
|
||||
log.error('Failed to cache channel data:')
|
||||
log.error(str(err))
|
||||
else:
|
||||
with open('/etc/janine/channels.json', 'r') as f:
|
||||
with open(channel_file, 'r') as f:
|
||||
channels = json.loads(f.read())
|
||||
|
||||
for key in channels.keys():
|
||||
@@ -219,6 +223,7 @@ class WarningBot:
|
||||
|
||||
# Configure sources
|
||||
self._sources = sources_from_config(config)
|
||||
self._data_dir = config['General'].get('DataDir', '/etc/janine')
|
||||
self._landkreis = config['General']['Landkreis']
|
||||
self._recipients = config['General']['Recipients'].split(',')
|
||||
self._refresh_timeout = int(config['General']['Timeout'])
|
||||
|
||||
Reference in New Issue
Block a user