diff --git a/src/bot.py b/src/bot.py index 0ef7815..0c1e367 100644 --- a/src/bot.py +++ b/src/bot.py @@ -1,13 +1,10 @@ -import json +import logging import telegram -from telegram.ext import CommandHandler from telegram.ext import Updater -import logging -import os from src.commands import * -from src.constants import dbPath, token +from src.constants import token from src.utils import createCommand # Main diff --git a/src/commands.py b/src/commands.py index 1c9651d..004c4e5 100644 --- a/src/commands.py +++ b/src/commands.py @@ -1,8 +1,7 @@ import re from src.database import Database -from src.utils import toJson -from src.request_configuration import RequestConfiguration +from src.utils import toJson, create helpMsg = """ Welcome! This bot monitors http changes! @@ -76,7 +75,7 @@ def touch(update, context): return "*Error:* %s cannot pass the format check" % url # Create - database.userRequests[user][name] = RequestConfiguration(url) + database.userRequests[user][name] = {'method': 'GET', 'url': url, 'headers': {}, 'data': None} database.save() return "%s is successfully created!" % name diff --git a/src/request_configuration.py b/src/request_configuration.py deleted file mode 100644 index 4596f2e..0000000 --- a/src/request_configuration.py +++ /dev/null @@ -1,14 +0,0 @@ -import requests - - -class RequestConfiguration: - headers = {} - payload = {} - - def __init__(self, url, method="GET"): - self.url = url - self.method = method - - # Create and execute http request - def create(self): - return requests.request(self.method, self.url, headers=self.headers, data=self.payload) diff --git a/src/utils.py b/src/utils.py index 54d8a21..a02878b 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,5 +1,6 @@ import json +import requests from telegram.ext import CommandHandler @@ -22,3 +23,8 @@ def createCommand(method): # Create handler for the wrapper command return CommandHandler(method.__name__, command, run_async=True) + + +# Create and execute http request +def create(req): + return requests.request(req['method'], req['url'], headers=req.get('headers', {}), data=req.get('payload', None))