From 4bf726695128d8c8a9bad8cba47a442cfff59630 Mon Sep 17 00:00:00 2001 From: Konrad Date: Fri, 27 Sep 2019 19:57:32 +0200 Subject: [PATCH] caching meals for 15 minutes --- HSMensaW_botA.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/HSMensaW_botA.py b/HSMensaW_botA.py index 4e2c45d..29dab4b 100644 --- a/HSMensaW_botA.py +++ b/HSMensaW_botA.py @@ -10,6 +10,7 @@ import traceback import urllib.request import xml.etree.ElementTree as ET from enum import Enum +from time import time from typing import Any from urllib.error import HTTPError @@ -54,6 +55,7 @@ essen = [] essen_eng = [] var = True datum = None +last_updated = 0.0 botID = -1 @@ -244,7 +246,11 @@ async def get_essen(only_today: bool) -> None: :param only_today: only current day; no download if the mensa is closed :return: """ - global datum, essen, essen_eng, var # , ctx + global datum, essen, essen_eng, var, last_updated # , ctx + if time() < last_updated + 900: + return + last_updated = time() + essen = [] essen_eng = [] try: