send message async
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,5 @@
|
|||||||
import telegram
|
|
||||||
from app import config_parser
|
from app import config_parser
|
||||||
|
import telegram
|
||||||
|
|
||||||
config = config_parser.ConfigParser().loadConfig()
|
config = config_parser.ConfigParser().loadConfig()
|
||||||
|
|
||||||
@@ -7,8 +7,7 @@ config = config_parser.ConfigParser().loadConfig()
|
|||||||
class telegramBot:
|
class telegramBot:
|
||||||
bot = None
|
bot = None
|
||||||
|
|
||||||
def __init__(self):
|
async def sendMessage(self, message):
|
||||||
self.bot = telegram.Bot(token=config['telegram']['token'])
|
self.bot = telegram.Bot(config['telegram']['token'])
|
||||||
|
async with self.bot:
|
||||||
def sendMessage(self, message):
|
await self.bot.sendMessage(chat_id=config['telegram']['chat_id'], text=str(message))
|
||||||
self.bot.sendMessage(chat_id=config['telegram']['chat_id'], text=str(message), parse_mode=telegram.ParseMode.HTML)
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import asyncio
|
||||||
|
|
||||||
import requests, json, pytz
|
import requests, json, pytz
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from time import sleep
|
from time import sleep
|
||||||
@@ -34,11 +36,11 @@ class timenetManager:
|
|||||||
return requests.post(furl, data=data, headers=headers)
|
return requests.post(furl, data=data, headers=headers)
|
||||||
|
|
||||||
def addMessage(self, message):
|
def addMessage(self, message):
|
||||||
print(message)
|
|
||||||
self.message_acumulator += message + "\n"
|
self.message_acumulator += message + "\n"
|
||||||
|
|
||||||
def sendReport(self):
|
def sendReport(self):
|
||||||
self.telegram.sendMessage(self.message_acumulator)
|
# self.telegram.sendMessage(self.message_acumulator)
|
||||||
|
asyncio.run(self.telegram.sendMessage(self.message_acumulator))
|
||||||
|
|
||||||
def updateTime(self):
|
def updateTime(self):
|
||||||
self.headers["tn-d"] = "\"" + datetime.now().astimezone(pytz.UTC).strftime("%Y-%m-%dT%H:%M:%SZ") + "\""
|
self.headers["tn-d"] = "\"" + datetime.now().astimezone(pytz.UTC).strftime("%Y-%m-%dT%H:%M:%SZ") + "\""
|
||||||
|
|||||||
Reference in New Issue
Block a user