Praxis_Bot/db.py
Alex Orid ada9d2ecb8 Added DB Module to the Twitch Module
Expanded main() a little to add DB_Module to the Twitch_Module.

Added a db_manager to the Twitch_Module class.

Added the nickname string to the db credential.
2020-09-23 15:01:15 -04:00

74 lines
1.9 KiB
Python

import credentials
import config as config
import pandas as pd
from sqlalchemy import create_engine
class db_module():
def __init__(self):
super().__init__()
self.dbCredential: credentials.DB_Credential
self.currentWorkingDB: str
self.engine = None
def setup_engine(self, credential: credentials.DB_Credential):
createEngine = True
if credential is None:
if self.dbCredential is None:
createEngine = False
else:
credential = self.dbCredential
if createEngine:
self.engine = create_engine(credential.engine_url)
self.currentWorkingDB = credential.databaseName
print("Engine Created")
def create_table(self, tableName: str = ""):
pass
def does_table_exist(self, tableName: str = ""):
pass
def delete_table(self, tableName: str = ""):
pass
# This was a old function used prior to the creation of this class. I need to remake it.
def get_data_old(self, tableName: str = "", key: str = ""):
table = '_channel_commands'
table = tableName
df = pd.read_sql_query('SELECT * FROM ' + table, engine)
stmt = "trigger == '" + key + "'"
temp = df.query(stmt)
result = temp.get("response")
# print(result)
i = len(temp.index.values)
if i == 1:
output = result[temp.index.values[0]]
pass
else:
output = "$$None$$"
return output
def get_data(self, tableName: str = "", key: str = ""):
pass
def insert_data(self, tableName: str = "", param: str = ""):
pass
def edit_data(self, tableName: str = "", key: str = "", param: str = ""):
pass
def delete_data(self, tableName: str = "", key: str = ""):
pass
if __name__ == "__main__":
db_connection = db_module()
db_connection.setup_engine()