From 74f39bb6219d6b56d1cfe1913d8ca2aa21676851 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Sun, 22 Nov 2020 14:13:50 -0500 Subject: [PATCH] [M] database: Separate from main function --- src/bot.py | 9 --------- src/commands.py | 6 ++++-- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/bot.py b/src/bot.py index f7d6332..383946e 100644 --- a/src/bot.py +++ b/src/bot.py @@ -8,22 +8,13 @@ import os from src.commands import * from src.constants import dbPath, token -from src.database import Database from src.utils import createCommand -database = Database() - # Main if __name__ == '__main__': # Initialize logger logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) - # Check database - if os.path.isfile(dbPath): - f = open(dbPath, 'r') - database = json.loads(f.read()) - f.close() - # Create bot bot = telegram.Bot(token=token) diff --git a/src/commands.py b/src/commands.py index 829bb8c..5b7c2e6 100644 --- a/src/commands.py +++ b/src/commands.py @@ -1,6 +1,6 @@ import re -from src.bot import database +from src.database import Database from src.utils import toJson from src.request_configuration import RequestConfiguration @@ -32,6 +32,8 @@ urlValidator = re.compile( r'(?::\d+)?' # optional port r'(?:/?|[/?]\S+)$', re.IGNORECASE) +database = Database() + def start(update, context): chat = update.effective_chat @@ -73,7 +75,7 @@ def touch(update, context): database.userRequests[user][name] = RequestConfiguration(url) database.save() - return "*%s* is successfully created!" % name + return "%s is successfully created!" % name def rm(update, context):