[F] Move sendRequest to utils to avoid circular import
This commit is contained in:
+2
-11
@@ -9,7 +9,7 @@ from telegram.ext import Updater, CallbackContext, Job
|
|||||||
|
|
||||||
from src.database import Database
|
from src.database import Database
|
||||||
from src.scheduler import Scheduler
|
from src.scheduler import Scheduler
|
||||||
from src.utils import toJson, create, dictToString, render, wrap
|
from src.utils import toJson, create, dictToString, render, wrap, sendRequest
|
||||||
|
|
||||||
helpMsg = """
|
helpMsg = """
|
||||||
Welcome! This bot monitors http changes!
|
Welcome! This bot monitors http changes!
|
||||||
@@ -44,15 +44,6 @@ scheduler: Scheduler
|
|||||||
updater: Updater
|
updater: Updater
|
||||||
|
|
||||||
|
|
||||||
def sendRequest(req: str):
|
|
||||||
r = create(req)
|
|
||||||
text = r.text
|
|
||||||
if r.headers['Content-Type'] == 'application/json':
|
|
||||||
text = dictToString(json.loads(text))
|
|
||||||
r.close()
|
|
||||||
return text
|
|
||||||
|
|
||||||
|
|
||||||
# Initialize bot
|
# Initialize bot
|
||||||
def init(bot: Bot, u: Updater):
|
def init(bot: Bot, u: Updater):
|
||||||
global updater
|
global updater
|
||||||
@@ -63,7 +54,7 @@ def init(bot: Bot, u: Updater):
|
|||||||
for user in database.users:
|
for user in database.users:
|
||||||
for request in database.reqs[user]:
|
for request in database.reqs[user]:
|
||||||
if request['enabled']:
|
if request['enabled']:
|
||||||
scheduler.startTask(user, request)
|
scheduler.start(user, request)
|
||||||
|
|
||||||
|
|
||||||
def start(update: Update, context: CallbackContext):
|
def start(update: Update, context: CallbackContext):
|
||||||
|
|||||||
+1
-2
@@ -4,9 +4,8 @@ from io import BytesIO
|
|||||||
|
|
||||||
from telegram.ext import Job, CallbackContext, Updater
|
from telegram.ext import Job, CallbackContext, Updater
|
||||||
|
|
||||||
from src.commands import sendRequest
|
|
||||||
from src.database import Database
|
from src.database import Database
|
||||||
from src.utils import wrap, render
|
from src.utils import wrap, render, sendRequest
|
||||||
|
|
||||||
|
|
||||||
class Scheduler:
|
class Scheduler:
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import difflib
|
||||||
import json
|
import json
|
||||||
import textwrap
|
import textwrap
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
@@ -96,3 +97,12 @@ def render(message):
|
|||||||
|
|
||||||
def wrap(string: str):
|
def wrap(string: str):
|
||||||
return '\n'.join([' ⏎\n '.join(textwrap.wrap(line, 120)) for line in string.splitlines()])
|
return '\n'.join([' ⏎\n '.join(textwrap.wrap(line, 120)) for line in string.splitlines()])
|
||||||
|
|
||||||
|
|
||||||
|
def sendRequest(req):
|
||||||
|
response = create(req)
|
||||||
|
text = response.text
|
||||||
|
if response.headers['Content-Type'] == 'application/json':
|
||||||
|
text = dictToString(json.loads(text))
|
||||||
|
response.close()
|
||||||
|
return text
|
||||||
|
|||||||
Reference in New Issue
Block a user