feat: Make the storage directory configurable
This commit is contained in:
parent
c9e9e78f79
commit
e130de8f92
@ -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)
|
||||
|
@ -73,6 +73,9 @@ class WarningBot:
|
||||
self._client = None
|
||||
self._refresh_timeout = 630 # 15min
|
||||
|
||||
# Configuration stuff
|
||||
self._data_dir = ''
|
||||
|
||||
self._load_config()
|
||||
|
||||
async def connect(self):
|
||||
@ -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'])
|
||||
|
Loading…
Reference in New Issue
Block a user