Compare commits

...

2 Commits

Author SHA1 Message Date
ccaee336dd Merge pull request 'Added DB Module to the Twitch Module' (#4) from DB-Credentials-Integration into credentials-class-idea
Reviewed-on: #4
2020-09-23 19:03:48 +00:00
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
5 changed files with 40 additions and 9 deletions

View File

@ -1,4 +1,5 @@
{
"nickname": "AnythingYouWant",
"username": "",
"password": "",
"ipAddress": "",

View File

@ -34,8 +34,9 @@ class Discord_Credential():
class DB_Credential():
# 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__()
self.nickname = nickname
self.username = username
self.password = password
self.ipAddress = ipAddress
@ -46,6 +47,7 @@ class DB_Credential():
def create_engine_url(self):
new_engine_url = "mysql+mysqlconnector://" + self.username + ":" + self.password + "@" + self.ipAddress + ":" + self.port + "/" + self.databaseName
self.engine_url = new_engine_url
return new_engine_url
class Credentials_Module():
@ -106,6 +108,9 @@ class Credentials_Module():
tobj = DB_Credential(**raw_json)
return tobj
def find_Credential(self):
pass
credentialLoadingFunctions = { # this is a mapping of the Credential enum to function pointers
Credential.Twitch_Credential: load_Twitch_Credential,
Credential.Discord_Credential: load_Discord_Credential,

18
db.py
View File

@ -1,4 +1,6 @@
import db_cred as db_credentials
import credentials
import config as config
import pandas as pd
from sqlalchemy import create_engine
@ -7,11 +9,21 @@ 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):
self.engine = create_engine(db_credentials.engine_url)
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 = ""):

13
main.py
View File

@ -22,14 +22,23 @@ def main():
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:
for cert in credentials_manager.Twitch_Credentials_List:
if cert.username == "praxis_bot":
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")
twitch_chat.twitchCredential = mainCert
twitch_chat.twitchCredential = twitchCert
print("Connecting to Channel: " + "thecuriousnerd")
twitch_chat.join_channel(None, "thecuriousnerd")

View File

@ -5,7 +5,7 @@ import twitch
import twitch.chat
import config as config
#import db
import db
import tts
import credentials
@ -14,7 +14,11 @@ class Twitch_Module():
def __init__(self):
super().__init__()
self.twitchCredential: credentials.Twitch_Credential
self.dbCredential: credentials.DB_Credential
self.db_manager: db.db_module = db.db_module()
self.chat: twitch.Chat
self.tts_enabled: bool = False
self.tts_whitelist_enabled: bool = False
self.links_allowed: bool = True