From 593292f7e78ce6a72dfc420c834a6c01d6266d21 Mon Sep 17 00:00:00 2001 From: Steven Tang Date: Fri, 30 Sep 2022 16:55:05 -0400 Subject: [PATCH 1/3] Adding CACHE_SEC --- wekan_ical_server.py | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/wekan_ical_server.py b/wekan_ical_server.py index 03c9e46..7b9379b 100644 --- a/wekan_ical_server.py +++ b/wekan_ical_server.py @@ -3,13 +3,14 @@ from http.server import BaseHTTPRequestHandler, HTTPServer import vobject import dateutil.parser - +import time LISTEN_HOST = os.environ.get("LISTEN_HOST", default="127.0.0.1") LISTEN_PORT = int(os.environ.get("LISTEN_PORT", default=8091)) WEKAN_HOST = os.environ["WEKAN_HOST"] WEKAN_USER = os.environ["WEKAN_USER"] WEKAN_PASSWORD = os.environ["WEKAN_PASSWORD"] +CACHE_SEC = int(os.environ.get("CACHE_SEC", default=-1)) # In seconds def create_ical_event(cal, board, card, card_info): @@ -22,26 +23,37 @@ def create_ical_event(cal, board, card, card_info): class MyHandler(BaseHTTPRequestHandler): + cachedResponse = b'' + lastUpdateTimestamp = 0 + def do_GET(s): - wekan_api = WekanApi( - WEKAN_HOST, {"username": WEKAN_USER, "password": WEKAN_PASSWORD} - ) - - cal = vobject.iCalendar() - boards = wekan_api.get_user_boards() - for board in boards: - cardslists = board.get_cardslists() - for cardslist in cardslists: - cards = cardslist.get_cards() - for card in cards: - info = card.get_card_info() - if "dueAt" in info and info["dueAt"] is not None: - create_ical_event(cal, board, card, info) + curTimestamp = time.time() + if curTimestamp - MyHandler.lastUpdateTimestamp > CACHE_SEC: + MyHandler.lastUpdateTimestamp = curTimestamp + + wekan_api = WekanApi( + WEKAN_HOST, {"username": WEKAN_USER, "password": WEKAN_PASSWORD} + ) + + cal = vobject.iCalendar() + boards = wekan_api.get_user_boards() + for board in boards: + if board.title == 'Templates': + continue + cardslists = board.get_cardslists() + for cardslist in cardslists: + cards = cardslist.get_cards() + for card in cards: + info = card.get_card_info() + if "dueAt" in info and info["dueAt"] is not None: + create_ical_event(cal, board, card, info) + + MyHandler.cacheResponse = cal.serialize().encode() s.send_response(200) s.send_header("Content-type", "text/calendar") s.end_headers() - s.wfile.write(cal.serialize().encode()) + s.wfile.write(MyHandler.cacheResponse) if __name__ == "__main__": From c238312a591497be1b9edd0c8732053f38b88996 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 30 Sep 2022 17:01:36 -0400 Subject: [PATCH 2/3] Add CACHE_SEC to docker-compose.yml --- docker-compose.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index dc581b3..96ad01f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,4 +13,5 @@ services: - WEKAN_USER=admin - WEKAN_PASSWORD=admin - LISTEN_HOST=0.0.0.0 - - LISTEN_PORT=8091 \ No newline at end of file + - LISTEN_PORT=8091 + - CACHE_SEC=-1 From 5939974f0b5ed85b0b2a8a8484d58ee5fef24b7b Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 30 Sep 2022 17:23:05 -0400 Subject: [PATCH 3/3] Bump wekan py api version --- requirements.in | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.in b/requirements.in index 89be613..27abf54 100644 --- a/requirements.in +++ b/requirements.in @@ -1,2 +1,2 @@ vobject -wekanapi @ git+https://github.com/wekan/wekan-python-api-client.git@7c4a75dd218a413c1f27d3db5acae56d63bb3706#subdirectory=src \ No newline at end of file +wekanapi @ git+https://github.com/wekan/wekan-python-api-client.git@82ae0b685fc2bd74a52401e2716551e59a3df019#subdirectory=src diff --git a/requirements.txt b/requirements.txt index 106947f..d42e0cf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,5 +20,5 @@ urllib3==1.26.3 # via requests vobject==0.9.6.1 # via -r requirements.in -git+https://github.com/wekan/wekan-python-api-client.git@7c4a75dd218a413c1f27d3db5acae56d63bb3706#subdirectory=src +git+https://github.com/wekan/wekan-python-api-client.git@82ae0b685fc2bd74a52401e2716551e59a3df019#subdirectory=src # via -r requirements.in