BukuBot/config.py
2024-05-31 11:42:37 +03:00

27 lines
857 B
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import buku
import os
import sys
class Configuration:
def init_db(jid_bare):
filename = jid_bare + '.db'
data_dir = Configuration.get_db_directory()
pathname = data_dir + '/' + filename
bookmarks_db = buku.BukuDb(dbfile=pathname)
return bookmarks_db
def get_db_directory():
if os.environ.get('HOME'):
data_home = os.path.join(os.environ.get('HOME'), '.local', 'share')
return os.path.join(data_home, 'bukubot')
elif sys.platform == 'win32':
data_home = os.environ.get('APPDATA')
if data_home is None:
return os.path.join(
os.path.dirname(__file__) + '/bukubot_data')
else:
return os.path.join(os.path.dirname(__file__) + '/bukubot_data')