From a252fb8573be304f916887db91e93da84a595dd7 Mon Sep 17 00:00:00 2001 From: Hofei90 <29521028+Hofei90@users.noreply.github.com> Date: Thu, 31 Oct 2019 16:02:11 +0100 Subject: [PATCH] add Postgresdb Option --- fotoablage_bot.py | 11 +++++++++-- vorlage_config_fotobot.toml | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/fotoablage_bot.py b/fotoablage_bot.py index 3078a35..8ca8a58 100644 --- a/fotoablage_bot.py +++ b/fotoablage_bot.py @@ -2,7 +2,7 @@ import os import time import toml -from peewee import SqliteDatabase +from peewee import SqliteDatabase, PostgresqlDatabase import db_modell as db from telegram_api import telegram_bot_api as api @@ -20,7 +20,14 @@ CONFIG = load_config() # Nur für Testzwecke! CONFIG["root_verzeichnis"] = SKRIPTPFAD -db.DB_PROXY.initialize(SqliteDatabase(os.path.join(SKRIPTPFAD, "datenbank.db3"))) +if CONFIG["db_adapter"] == "sqlite": + db.DB_PROXY.initialize(SqliteDatabase(os.path.join(SKRIPTPFAD, "datenbank.db3"))) +elif CONFIG["db_adapter"] == "postgres": + db.DB_PROXY.initialize(PostgresqlDatabase(CONFIG["pg"]["database"], + user=CONFIG["pg"]["user"], + password=CONFIG["pg"]["password"])) +else: + raise NameError("db_adapter: {} nicht gefunden".format(CONFIG["db_adapter"])) class FotoBot(api.Bot): diff --git a/vorlage_config_fotobot.toml b/vorlage_config_fotobot.toml index bccd501..dd0b4aa 100644 --- a/vorlage_config_fotobot.toml +++ b/vorlage_config_fotobot.toml @@ -3,3 +3,9 @@ token = "" root_verzeichnis = "" erlaubte_telegram_ids = [] +db_adapter = "sqlite" # (sqlite | postgres) + +[pg] + database = "" + user = "" + password = ""