mirror of
https://github.com/Xevion/contest-assistant.git
synced 2025-12-06 13:14:40 -06:00
running bot with database, switch to helper function for testing
This commit is contained in:
@@ -5,6 +5,7 @@ import os
|
|||||||
BASE_DIR = os.path.dirname(os.path.abspath(os.path.join(__file__, '..')))
|
BASE_DIR = os.path.dirname(os.path.abspath(os.path.join(__file__, '..')))
|
||||||
TOKEN = os.path.join(BASE_DIR, 'token.dat')
|
TOKEN = os.path.join(BASE_DIR, 'token.dat')
|
||||||
DATABASE = os.path.join(BASE_DIR, 'database.db')
|
DATABASE = os.path.join(BASE_DIR, 'database.db')
|
||||||
|
DATABASE_URI = f'sqlite:///{DATABASE}'
|
||||||
|
|
||||||
# Other constants
|
# Other constants
|
||||||
LOGGING_LEVEL = logging.DEBUG
|
LOGGING_LEVEL = logging.DEBUG
|
||||||
|
|||||||
13
main.py
13
main.py
@@ -1,11 +1,19 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
|
from sqlalchemy.engine import Engine
|
||||||
|
|
||||||
from bot import constants
|
from bot import constants
|
||||||
from bot.bot import ContestBot
|
from bot.bot import ContestBot
|
||||||
from bot.models import Base
|
from bot.models import Base
|
||||||
|
|
||||||
|
|
||||||
|
def load_db(url=constants.DATABASE_URI) -> Engine:
|
||||||
|
engine = create_engine(url)
|
||||||
|
Base.metadata.create_all(engine)
|
||||||
|
return engine
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
logger = logging.getLogger(__file__)
|
logger = logging.getLogger(__file__)
|
||||||
logger.setLevel(constants.LOGGING_LEVEL)
|
logger.setLevel(constants.LOGGING_LEVEL)
|
||||||
@@ -17,10 +25,9 @@ if __name__ == "__main__":
|
|||||||
logging.StreamHandler()
|
logging.StreamHandler()
|
||||||
])
|
])
|
||||||
|
|
||||||
initial_extensions = ['contest.cogs.contest']
|
initial_extensions = ['bot.cogs.contest']
|
||||||
|
|
||||||
engine = create_engine(constants.DATABASE)
|
engine = load_db()
|
||||||
Base.metadata.create_all(engine)
|
|
||||||
bot = ContestBot(engine, description='A assistant for the Photography Lounge\'s monday contests')
|
bot = ContestBot(engine, description='A assistant for the Photography Lounge\'s monday contests')
|
||||||
|
|
||||||
for extension in initial_extensions:
|
for extension in initial_extensions:
|
||||||
|
|||||||
Reference in New Issue
Block a user