caching bot id (web request is done only once)
Signed-off-by: klux2 <k.lux.gm@gmail.com>
This commit is contained in:
parent
01248e449e
commit
4946837240
1 changed files with 9 additions and 5 deletions
|
@ -46,6 +46,8 @@ essen = []
|
||||||
var = True
|
var = True
|
||||||
datum = None
|
datum = None
|
||||||
|
|
||||||
|
botID = -1
|
||||||
|
|
||||||
|
|
||||||
class HSMensaW(telepot.aio.helper.ChatHandler):
|
class HSMensaW(telepot.aio.helper.ChatHandler):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -233,11 +235,13 @@ async def get_essen(only_today: bool) -> None:
|
||||||
|
|
||||||
|
|
||||||
def get_bot_id() -> int:
|
def get_bot_id() -> int:
|
||||||
api_url = "https://api.telegram.org/bot" + telegram_bot_token + "/getMe"
|
global botID
|
||||||
with urllib.request.urlopen(api_url) as response:
|
if botID == -1:
|
||||||
data = json.load(response)
|
api_url = "https://api.telegram.org/bot" + telegram_bot_token + "/getMe"
|
||||||
bot_id = data["result"]["id"]
|
with urllib.request.urlopen(api_url) as response:
|
||||||
return bot_id
|
data = json.load(response)
|
||||||
|
botID = data["result"]["id"]
|
||||||
|
return botID
|
||||||
|
|
||||||
|
|
||||||
def get_chat_name(msg: dict) -> str:
|
def get_chat_name(msg: dict) -> str:
|
||||||
|
|
Loading…
Reference in a new issue