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'])