[-] Remove RequestConfiguration class, use dict instead
This commit is contained in:
+2
-5
@@ -1,13 +1,10 @@
|
|||||||
import json
|
import logging
|
||||||
|
|
||||||
import telegram
|
import telegram
|
||||||
from telegram.ext import CommandHandler
|
|
||||||
from telegram.ext import Updater
|
from telegram.ext import Updater
|
||||||
import logging
|
|
||||||
import os
|
|
||||||
|
|
||||||
from src.commands import *
|
from src.commands import *
|
||||||
from src.constants import dbPath, token
|
from src.constants import token
|
||||||
from src.utils import createCommand
|
from src.utils import createCommand
|
||||||
|
|
||||||
# Main
|
# Main
|
||||||
|
|||||||
+2
-3
@@ -1,8 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from src.database import Database
|
from src.database import Database
|
||||||
from src.utils import toJson
|
from src.utils import toJson, create
|
||||||
from src.request_configuration import RequestConfiguration
|
|
||||||
|
|
||||||
helpMsg = """
|
helpMsg = """
|
||||||
Welcome! This bot monitors http changes!
|
Welcome! This bot monitors http changes!
|
||||||
@@ -76,7 +75,7 @@ def touch(update, context):
|
|||||||
return "*Error:* %s cannot pass the format check" % url
|
return "*Error:* %s cannot pass the format check" % url
|
||||||
|
|
||||||
# Create
|
# Create
|
||||||
database.userRequests[user][name] = RequestConfiguration(url)
|
database.userRequests[user][name] = {'method': 'GET', 'url': url, 'headers': {}, 'data': None}
|
||||||
database.save()
|
database.save()
|
||||||
|
|
||||||
return "%s is successfully created!" % name
|
return "%s is successfully created!" % name
|
||||||
|
|||||||
@@ -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)
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
|
import requests
|
||||||
from telegram.ext import CommandHandler
|
from telegram.ext import CommandHandler
|
||||||
|
|
||||||
|
|
||||||
@@ -22,3 +23,8 @@ def createCommand(method):
|
|||||||
|
|
||||||
# Create handler for the wrapper command
|
# Create handler for the wrapper command
|
||||||
return CommandHandler(method.__name__, command, run_async=True)
|
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))
|
||||||
|
|||||||
Reference in New Issue
Block a user