From e130de8f9291d29f3b3320a4f53fdb9ce9e2c28b Mon Sep 17 00:00:00 2001 From: Alexander PapaTutuWawa Date: Thu, 17 Sep 2020 14:24:53 +0200 Subject: [PATCH] feat: Make the storage directory configurable --- janine.example.conf | 1 + janine/janine.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/janine.example.conf b/janine.example.conf index 611fc76..34cc998 100644 --- a/janine.example.conf +++ b/janine.example.conf @@ -6,6 +6,7 @@ BIWAPP = y # Warnmeldungen Landkreis = Stuttgart # Warnungen für diesen Landkreis weiterleiten Recipients = some.user@xmpp.server,other@xmpp.server # Empfänger Timeout=630 # Zeit in Sekunden nach welcher nach neuen Warnungen geschaut wird +DataDir = /etc/janine/data # Verzeichnis für persistente Daten [Bot] Avatar = /etc/janine/avatar.png # Bot Avatar (Optional) diff --git a/janine/janine.py b/janine/janine.py index 6620c87..ae3a60d 100644 --- a/janine/janine.py +++ b/janine/janine.py @@ -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'])