-
Notifications
You must be signed in to change notification settings - Fork 11
/
run.py
45 lines (35 loc) · 1.26 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from bot.LambdaSantaBot import LambdaSantaBot
from bot.LocalSantaBot import LocalSantaBot
from bot.DBConnection import DBConnection
from configparser import ConfigParser
from os.path import isfile, normpath
if __name__ == '__main__':
bot_database_file = "bot.sqlite"
if not isfile(bot_database_file):
open(bot_database_file, 'w').close()
dbConnectionString = 'sqlite:///' + bot_database_file
dbConnection = DBConnection(dbConnectionString)
bot = LocalSantaBot(dbConnection)
dbConnection.createAll()
bot.main()
def lambda_handler(event, context):
config = ConfigParser()
configPath = normpath('config/config.ini')
config.read(configPath)
url = config.get('db', 'url')
port = config.get('db', 'port')
username = config.get('db', 'username')
password = config.get('db', 'password')
databaseName = config.get('db', 'database_name')
dbConnectionString = (
f"mysql+mysqlconnector://"
f"{username}:{password}"
f"@{url}:{port}/{databaseName}"
)
dbConnection = DBConnection(dbConnectionString)
bot = LambdaSantaBot(dbConnection)
dbConnection.createAll()
bot.process_message(event)
return {
'statusCode': 200,
}