feat: Make the storage directory configurable

This commit is contained in:
PapaTutuWawa 2020-09-17 14:24:53 +02:00
parent c9e9e78f79
commit e130de8f92
2 changed files with 10 additions and 4 deletions

View File

@ -6,6 +6,7 @@ BIWAPP = y # Warnmeldungen
Landkreis = Stuttgart # Warnungen für diesen Landkreis weiterleiten Landkreis = Stuttgart # Warnungen für diesen Landkreis weiterleiten
Recipients = some.user@xmpp.server,other@xmpp.server # Empfänger Recipients = some.user@xmpp.server,other@xmpp.server # Empfänger
Timeout=630 # Zeit in Sekunden nach welcher nach neuen Warnungen geschaut wird Timeout=630 # Zeit in Sekunden nach welcher nach neuen Warnungen geschaut wird
DataDir = /etc/janine/data # Verzeichnis für persistente Daten
[Bot] [Bot]
Avatar = /etc/janine/avatar.png # Bot Avatar (Optional) Avatar = /etc/janine/avatar.png # Bot Avatar (Optional)

View File

@ -73,6 +73,9 @@ class WarningBot:
self._client = None self._client = None
self._refresh_timeout = 630 # 15min self._refresh_timeout = 630 # 15min
# Configuration stuff
self._data_dir = ''
self._load_config() self._load_config()
async def connect(self): async def connect(self):
@ -85,19 +88,20 @@ class WarningBot:
# First we check if the entered Landkreis is valid # First we check if the entered Landkreis is valid
channels = {} 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') log.debug('Requesting search channels')
req = requests.get(MiscDataSources.channels()) req = requests.get(MiscDataSources.channels())
channels = json.loads(req.text) channels = json.loads(req.text)
try: try:
with open('/etc/janine/channels.json', 'w') as f: with open(channel_file, 'w') as f:
f.write(json.dumps(channels)) f.write(json.dumps(channels))
except Exception as err: except Exception as err:
log.error('Failed to cache channel data:') log.error('Failed to cache channel data:')
log.error(str(err)) log.error(str(err))
else: else:
with open('/etc/janine/channels.json', 'r') as f: with open(channel_file, 'r') as f:
channels = json.loads(f.read()) channels = json.loads(f.read())
for key in channels.keys(): for key in channels.keys():
@ -219,6 +223,7 @@ class WarningBot:
# Configure sources # Configure sources
self._sources = sources_from_config(config) self._sources = sources_from_config(config)
self._data_dir = config['General'].get('DataDir', '/etc/janine')
self._landkreis = config['General']['Landkreis'] self._landkreis = config['General']['Landkreis']
self._recipients = config['General']['Recipients'].split(',') self._recipients = config['General']['Recipients'].split(',')
self._refresh_timeout = int(config['General']['Timeout']) self._refresh_timeout = int(config['General']['Timeout'])