Skip to content

Commit 012423f

Browse files
committed
installation routine works
1 parent e6470a9 commit 012423f

File tree

8 files changed

+151
-182
lines changed

8 files changed

+151
-182
lines changed

Diff for: .idea/workspace.xml

+120-152
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Helper.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1+
import os
2+
from global_constants import DB_NAME
13

2-
""" Converts a dictionary to a list by only adding
3-
the keys of the dict to the list. """
4-
def dict2listByKey(dict):
5-
list = []
6-
for key in dict:
7-
list.append(key)
8-
return list
9-
10-
4+
def doesDbExist():
5+
return os.path.exists(DB_NAME)

Diff for: entities/ent_base_model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
class BaseModel(Model):
66
class Meta:
77
# Determine which db to use
8-
database = db
8+
database = db

Diff for: global_constants.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# DO NOT PUT ANY LOGIC IN THIS FILE
2+
3+
# (MUST NOT BE CHANGED!) -> bound due to chatterBot
4+
DB_NAME = "db.sqlite3"

Diff for: mgr/mgr_db.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
import sys
12
from peewee import *
2-
from starterkit.conf import db
3+
from entities.ent_enabled_module import EnabledModule
34

4-
def db_loadEnabledModules():
5-
# TODO: online (https://sqliteonline.com/) all sql tables are created, but here it seems that only the chatterbot ones are created
6-
print(str(
7-
db.get_tables()
8-
))
5+
# TODO: Import all modules dynamically
6+
from modules.get_welcome_msg import get_welcome_msg
7+
from modules.get_random_question import get_random_question
8+
from modules.get_random_fact import get_random_fact
99

10-
db_loadEnabledModules()
10+
def db_loadEnabledModules():
11+
enabled_modules = []
12+
for module in EnabledModule.select():
13+
enabled_modules.append(
14+
# str to class
15+
getattr(sys.modules[__name__], module.class_name)
16+
)
17+
return enabled_modules

Diff for: mgr/mgr_voices.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
#!/usr/bin/python3
2-
from modules.get_welcome_msg import get_welcome_msg
3-
from modules.get_random_fact.get_random_fact import get_random_fact
4-
from modules.get_random_question.get_random_question import get_random_question
52
from starterkit.get_smart_answer import get_smart_answer
3+
from mgr.mgr_db import db_loadEnabledModules
64

75
# Speech to Text and reverse
86

97
from pocketsphinx import LiveSpeech
108
import pyttsx3
119

12-
# TODO REMOVE AND REPLACE WITH DB (no import)
13-
ENABLED_MODULES = [
14-
get_welcome_msg,
15-
get_random_question,
16-
get_random_fact
17-
]
10+
ENABLED_MODULES = db_loadEnabledModules() # do only once for better performance
1811

1912
# OUTPUT / Assistant Voice/Response +++++++++++++++
2013
assistantVoice = pyttsx3.init()
@@ -31,7 +24,7 @@ def configureAssistantVoice():
3124
def getAssistantResponse(phrase):
3225
for module in ENABLED_MODULES:
3326
# text should be always a str, bc. we validated this in main.py
34-
if any(x in str(phrase) for x in module.chat_keywords):
27+
if any(x in str(phrase) for x in module.chat_keywords): # TODO: get keywords from db
3528
answer = str(module.getAnswer(phrase))
3629
break
3730

Diff for: modules/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
# Automatically imports all modules
3+
# Automatically imports all modu
44
for module in os.listdir(os.path.dirname(__file__)):
55
if module == '__init__.py' or os.path.isdir(__file__): #module[-3:] != '.py'
66
continue

Diff for: starterkit/conf.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import os, sys
12
from chatterbot import ChatBot
23
from peewee import SqliteDatabase
4+
from global_constants import DB_NAME
35

46
""" As get_smart_answer is no regular module, the .conf-file here looks completely different. """
57

6-
# Set database file (MUST NOT BE CHANGED!)
7-
db = SqliteDatabase('db.sqlite3')
8+
# Set database file
9+
db = SqliteDatabase(DB_NAME)
810

911
# Set up chatbot
1012
chatbot = ChatBot(

0 commit comments

Comments
 (0)