[M] database: Separate from main function
This commit is contained in:
@@ -8,22 +8,13 @@ import os
|
|||||||
|
|
||||||
from src.commands import *
|
from src.commands import *
|
||||||
from src.constants import dbPath, token
|
from src.constants import dbPath, token
|
||||||
from src.database import Database
|
|
||||||
from src.utils import createCommand
|
from src.utils import createCommand
|
||||||
|
|
||||||
database = Database()
|
|
||||||
|
|
||||||
# Main
|
# Main
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# Initialize logger
|
# Initialize logger
|
||||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
|
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
|
# Create bot
|
||||||
bot = telegram.Bot(token=token)
|
bot = telegram.Bot(token=token)
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -1,6 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from src.bot import database
|
from src.database import Database
|
||||||
from src.utils import toJson
|
from src.utils import toJson
|
||||||
from src.request_configuration import RequestConfiguration
|
from src.request_configuration import RequestConfiguration
|
||||||
|
|
||||||
@@ -32,6 +32,8 @@ urlValidator = re.compile(
|
|||||||
r'(?::\d+)?' # optional port
|
r'(?::\d+)?' # optional port
|
||||||
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
|
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
|
||||||
|
|
||||||
|
database = Database()
|
||||||
|
|
||||||
|
|
||||||
def start(update, context):
|
def start(update, context):
|
||||||
chat = update.effective_chat
|
chat = update.effective_chat
|
||||||
@@ -73,7 +75,7 @@ def touch(update, context):
|
|||||||
database.userRequests[user][name] = RequestConfiguration(url)
|
database.userRequests[user][name] = RequestConfiguration(url)
|
||||||
database.save()
|
database.save()
|
||||||
|
|
||||||
return "*%s* is successfully created!" % name
|
return "%s is successfully created!" % name
|
||||||
|
|
||||||
|
|
||||||
def rm(update, context):
|
def rm(update, context):
|
||||||
|
|||||||
Reference in New Issue
Block a user