caching bot id (web request is done only once)

Signed-off-by: klux2 <k.lux.gm@gmail.com>
This commit is contained in:
klux2 2019-07-04 13:37:04 +02:00
parent 01248e449e
commit 4946837240

View file

@ -46,6 +46,8 @@ essen = []
var = True
datum = None
botID = -1
class HSMensaW(telepot.aio.helper.ChatHandler):
@staticmethod
@ -233,11 +235,13 @@ async def get_essen(only_today: bool) -> None:
def get_bot_id() -> int:
api_url = "https://api.telegram.org/bot" + telegram_bot_token + "/getMe"
with urllib.request.urlopen(api_url) as response:
data = json.load(response)
bot_id = data["result"]["id"]
return bot_id
global botID
if botID == -1:
api_url = "https://api.telegram.org/bot" + telegram_bot_token + "/getMe"
with urllib.request.urlopen(api_url) as response:
data = json.load(response)
botID = data["result"]["id"]
return botID
def get_chat_name(msg: dict) -> str: