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