Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ services:
- WEKAN_USER=admin
- WEKAN_PASSWORD=admin
- LISTEN_HOST=0.0.0.0
- LISTEN_PORT=8091
- LISTEN_PORT=8091
- CACHE_SEC=-1
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
vobject
wekanapi @ git+https://github.com/wekan/wekan-python-api-client.git@7c4a75dd218a413c1f27d3db5acae56d63bb3706#subdirectory=src
wekanapi @ git+https://github.com/wekan/wekan-python-api-client.git@82ae0b685fc2bd74a52401e2716551e59a3df019#subdirectory=src
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
44 changes: 28 additions & 16 deletions wekan_ical_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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__":
Expand Down