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.
This commit is contained in:
parent
ff4c21a747
commit
ada9d2ecb8
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"nickname": "AnythingYouWant",
|
||||||
"username": "",
|
"username": "",
|
||||||
"password": "",
|
"password": "",
|
||||||
"ipAddress": "",
|
"ipAddress": "",
|
||||||
|
|||||||
@ -34,8 +34,9 @@ class Discord_Credential():
|
|||||||
|
|
||||||
class DB_Credential():
|
class DB_Credential():
|
||||||
# engine = "mysql+mysqlconnector://root:password@localhost:3306/DatabaseName"
|
# engine = "mysql+mysqlconnector://root:password@localhost:3306/DatabaseName"
|
||||||
def __init__(self, username, password, ipAddress, port, databaseName, engine_url):
|
def __init__(self, nickname, username, password, ipAddress, port, databaseName, engine_url):
|
||||||
#super().__init__()
|
#super().__init__()
|
||||||
|
self.nickname = nickname
|
||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
self.ipAddress = ipAddress
|
self.ipAddress = ipAddress
|
||||||
@ -46,6 +47,7 @@ class DB_Credential():
|
|||||||
def create_engine_url(self):
|
def create_engine_url(self):
|
||||||
new_engine_url = "mysql+mysqlconnector://" + self.username + ":" + self.password + "@" + self.ipAddress + ":" + self.port + "/" + self.databaseName
|
new_engine_url = "mysql+mysqlconnector://" + self.username + ":" + self.password + "@" + self.ipAddress + ":" + self.port + "/" + self.databaseName
|
||||||
self.engine_url = new_engine_url
|
self.engine_url = new_engine_url
|
||||||
|
return new_engine_url
|
||||||
|
|
||||||
|
|
||||||
class Credentials_Module():
|
class Credentials_Module():
|
||||||
@ -106,6 +108,9 @@ class Credentials_Module():
|
|||||||
tobj = DB_Credential(**raw_json)
|
tobj = DB_Credential(**raw_json)
|
||||||
return tobj
|
return tobj
|
||||||
|
|
||||||
|
def find_Credential(self):
|
||||||
|
pass
|
||||||
|
|
||||||
credentialLoadingFunctions = { # this is a mapping of the Credential enum to function pointers
|
credentialLoadingFunctions = { # this is a mapping of the Credential enum to function pointers
|
||||||
Credential.Twitch_Credential: load_Twitch_Credential,
|
Credential.Twitch_Credential: load_Twitch_Credential,
|
||||||
Credential.Discord_Credential: load_Discord_Credential,
|
Credential.Discord_Credential: load_Discord_Credential,
|
||||||
|
|||||||
18
db.py
18
db.py
@ -1,4 +1,6 @@
|
|||||||
import db_cred as db_credentials
|
import credentials
|
||||||
|
|
||||||
|
import config as config
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
@ -7,11 +9,21 @@ from sqlalchemy import create_engine
|
|||||||
class db_module():
|
class db_module():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
self.dbCredential: credentials.DB_Credential
|
||||||
self.currentWorkingDB: str
|
self.currentWorkingDB: str
|
||||||
self.engine = None
|
self.engine = None
|
||||||
|
|
||||||
def setup_engine(self):
|
def setup_engine(self, credential: credentials.DB_Credential):
|
||||||
self.engine = create_engine(db_credentials.engine_url)
|
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")
|
print("Engine Created")
|
||||||
|
|
||||||
def create_table(self, tableName: str = ""):
|
def create_table(self, tableName: str = ""):
|
||||||
|
|||||||
13
main.py
13
main.py
@ -22,14 +22,23 @@ def main():
|
|||||||
|
|
||||||
twitch_chat = twitch_script.Twitch_Module()
|
twitch_chat = twitch_script.Twitch_Module()
|
||||||
|
|
||||||
|
dbCert: credentials.DB_Credential
|
||||||
|
if credentials_manager.DB_Credentials_List is not None:
|
||||||
|
for cert in credentials_manager.DB_Credentials_List:
|
||||||
|
if cert.nickname == "praxis_bot":
|
||||||
|
print("DB Certificate Found: {" + cert.nickname + "}")
|
||||||
|
dbCert = cert
|
||||||
|
|
||||||
|
twitchCert: credentials.Twitch_Credential
|
||||||
if credentials_manager.Twitch_Credentials_List is not None:
|
if credentials_manager.Twitch_Credentials_List is not None:
|
||||||
for cert in credentials_manager.Twitch_Credentials_List:
|
for cert in credentials_manager.Twitch_Credentials_List:
|
||||||
if cert.username == "praxis_bot":
|
if cert.username == "praxis_bot":
|
||||||
print("Twitch Certificate Found: {" + cert.username + "}")
|
print("Twitch Certificate Found: {" + cert.username + "}")
|
||||||
mainCert = cert
|
twitchCert = cert
|
||||||
|
|
||||||
|
twitch_chat.db_manager.setup_engine(dbCert)
|
||||||
print("Loading Credential: {" + cert.username + "} into Twitch_Module")
|
print("Loading Credential: {" + cert.username + "} into Twitch_Module")
|
||||||
twitch_chat.twitchCredential = mainCert
|
twitch_chat.twitchCredential = twitchCert
|
||||||
print("Connecting to Channel: " + "thecuriousnerd")
|
print("Connecting to Channel: " + "thecuriousnerd")
|
||||||
twitch_chat.join_channel(None, "thecuriousnerd")
|
twitch_chat.join_channel(None, "thecuriousnerd")
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import twitch
|
|||||||
import twitch.chat
|
import twitch.chat
|
||||||
|
|
||||||
import config as config
|
import config as config
|
||||||
#import db
|
import db
|
||||||
import tts
|
import tts
|
||||||
|
|
||||||
import credentials
|
import credentials
|
||||||
@ -14,7 +14,11 @@ class Twitch_Module():
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.twitchCredential: credentials.Twitch_Credential
|
self.twitchCredential: credentials.Twitch_Credential
|
||||||
|
self.dbCredential: credentials.DB_Credential
|
||||||
|
|
||||||
|
self.db_manager: db.db_module = db.db_module()
|
||||||
self.chat: twitch.Chat
|
self.chat: twitch.Chat
|
||||||
|
|
||||||
self.tts_enabled: bool = False
|
self.tts_enabled: bool = False
|
||||||
self.tts_whitelist_enabled: bool = False
|
self.tts_whitelist_enabled: bool = False
|
||||||
self.links_allowed: bool = True
|
self.links_allowed: bool = True
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user