From 79c865552e21a45f4d1c30da48273c01416a7c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Fri, 2 Sep 2022 19:21:15 +0000 Subject: [PATCH] quick and dirty calendar listing --- api/ovdashboard_api/__init__.py | 18 ++++- api/ovdashboard_api/routers/__init__.py | 3 +- api/ovdashboard_api/routers/calendar.py | 14 ++++ api/poetry.lock | 95 ++++++++++++++++++++++++- api/pyproject.toml | 1 + 5 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 api/ovdashboard_api/routers/calendar.py diff --git a/api/ovdashboard_api/__init__.py b/api/ovdashboard_api/__init__.py index 0647a75..66b70fc 100644 --- a/api/ovdashboard_api/__init__.py +++ b/api/ovdashboard_api/__init__.py @@ -1,11 +1,12 @@ import functools from typing import Any -from webdav3.client import Client, Resource +import caldav +from webdav3 import client as WebDAVclient from .config import SETTINGS -_WEBDAV_CLIENT = Client({ +_WEBDAV_CLIENT = WebDAVclient.Client({ "webdav_hostname": SETTINGS.webdav_url, "webdav_login": SETTINGS.dav_username, "webdav_password": SETTINGS.dav_password, @@ -13,9 +14,20 @@ _WEBDAV_CLIENT = Client({ @functools.lru_cache -def webdav_resource(remote_path: Any) -> Resource: +def webdav_resource(remote_path: Any) -> WebDAVclient.Resource: return _WEBDAV_CLIENT.resource(remote_path) def webdav_list(remote_path: str) -> list: return _WEBDAV_CLIENT.list(remote_path) + + +_CALDAV_CLIENT = caldav.DAVClient( + url=SETTINGS.caldav_url, + username=SETTINGS.dav_username, + password=SETTINGS.dav_password, +) + + +def caldav_principal() -> caldav.Principal: + return _CALDAV_CLIENT.principal() diff --git a/api/ovdashboard_api/routers/__init__.py b/api/ovdashboard_api/routers/__init__.py index f774243..2bc4c78 100644 --- a/api/ovdashboard_api/routers/__init__.py +++ b/api/ovdashboard_api/routers/__init__.py @@ -7,11 +7,12 @@ This file: Main API router definition. from fastapi import APIRouter from ..config import SETTINGS -from . import image, text +from . import calendar, image, text main_router = APIRouter(prefix=f"/{SETTINGS.api_v1_prefix}") main_router.include_router(text.router) main_router.include_router(image.router) +main_router.include_router(calendar.router) __all__ = [ "main_router", diff --git a/api/ovdashboard_api/routers/calendar.py b/api/ovdashboard_api/routers/calendar.py new file mode 100644 index 0000000..c2e330c --- /dev/null +++ b/api/ovdashboard_api/routers/calendar.py @@ -0,0 +1,14 @@ +from fastapi import APIRouter + +from .. import caldav_principal + +router = APIRouter(prefix="/calendar", tags=["calendar"]) + + +@router.get("/list", response_model=list[str]) +async def list_calendars() -> list[str]: + principal = caldav_principal() + return list( + cal.name + for cal in principal.calendars() + ) diff --git a/api/poetry.lock b/api/poetry.lock index 779accb..5e20d06 100644 --- a/api/poetry.lock +++ b/api/poetry.lock @@ -23,6 +23,22 @@ category = "main" optional = false python-versions = ">=3.6" +[[package]] +name = "caldav" +version = "0.9.1" +description = "CalDAV (RFC4791) client library" +category = "main" +optional = false +python-versions = "*" + +[package.dependencies] +lxml = "*" +pytz = "*" +requests = "*" +six = "*" +tzlocal = "*" +vobject = "*" + [[package]] name = "certifi" version = "2022.6.15" @@ -189,6 +205,25 @@ python-versions = ">=3.5" [package.extras] cli = ["click (>=5.0)"] +[[package]] +name = "pytz" +version = "2022.2.1" +description = "World timezone definitions, modern and historical" +category = "main" +optional = false +python-versions = "*" + +[[package]] +name = "pytz-deprecation-shim" +version = "0.1.0.post0" +description = "Shims to make deprecation of pytz easier" +category = "main" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7" + +[package.dependencies] +tzdata = {version = "*", markers = "python_version >= \"3.6\""} + [[package]] name = "requests" version = "2.28.1" @@ -246,6 +281,30 @@ category = "main" optional = false python-versions = ">=3.7" +[[package]] +name = "tzdata" +version = "2022.2" +description = "Provider of IANA time zone data" +category = "main" +optional = false +python-versions = ">=2" + +[[package]] +name = "tzlocal" +version = "4.2" +description = "tzinfo object for the local timezone" +category = "main" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +pytz-deprecation-shim = "*" +tzdata = {version = "*", markers = "platform_system == \"Windows\""} + +[package.extras] +devenv = ["black", "pyroma", "pytest-cov", "zest.releaser"] +test = ["pytest (>=4.3)", "pytest-mock (>=3.3)"] + [[package]] name = "urllib3" version = "1.26.12" @@ -274,6 +333,17 @@ h11 = ">=0.8" [package.extras] standard = ["colorama (>=0.4)", "httptools (>=0.4.0)", "python-dotenv (>=0.13)", "pyyaml (>=5.1)", "uvloop (>=0.14.0,!=0.15.0,!=0.15.1)", "watchfiles (>=0.13)", "websockets (>=10.0)"] +[[package]] +name = "vobject" +version = "0.9.6.1" +description = "A full-featured Python package for parsing and creating iCalendar and vCard files" +category = "main" +optional = false +python-versions = "*" + +[package.dependencies] +python-dateutil = ">=2.4.0" + [[package]] name = "webdavclient3" version = "3.14.5" @@ -302,7 +372,7 @@ testing = ["func-timeout", "jaraco.itertools", "pytest (>=6)", "pytest-black (>= [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "aec58b629996d82fcafca1b5c31af78e4433c7059b8f98b47022ddefdf61dac1" +content-hash = "e6a77257433600e323c267400376a4d16ddbae3d72f5d3a2a1b976f02fa36874" [metadata.files] anyio = [ @@ -313,6 +383,10 @@ async-lru = [ {file = "async-lru-1.0.3.tar.gz", hash = "sha256:c2cb9b2915eb14e6cf3e717154b40f715bf90e596d73623677affd0d1fbcd32a"}, {file = "async_lru-1.0.3-py3-none-any.whl", hash = "sha256:ea692c303feb6211ff260d230dae1583636f13e05c9ae616eada77855b7f415c"}, ] +caldav = [ + {file = "caldav-0.9.1-py3-none-any.whl", hash = "sha256:0a3854adbb0c4e1fe042e9eed26dffbf1e696705c87cadd8f3ceb39cf4b4b274"}, + {file = "caldav-0.9.1.tar.gz", hash = "sha256:5f11476eba04b677b5fcdb26939f0a9ebb7ec21d8a57dc60de4c0db0e08ca21f"}, +] certifi = [ {file = "certifi-2022.6.15-py3-none-any.whl", hash = "sha256:fe86415d55e84719d75f8b69414f6438ac3547d2078ab91b67e779ef69378412"}, {file = "certifi-2022.6.15.tar.gz", hash = "sha256:84c85a9078b11105f04f3036a9482ae10e4621616db313fe045dd24743a0820d"}, @@ -527,6 +601,14 @@ python-dotenv = [ {file = "python-dotenv-0.20.0.tar.gz", hash = "sha256:b7e3b04a59693c42c36f9ab1cc2acc46fa5df8c78e178fc33a8d4cd05c8d498f"}, {file = "python_dotenv-0.20.0-py3-none-any.whl", hash = "sha256:d92a187be61fe482e4fd675b6d52200e7be63a12b724abbf931a40ce4fa92938"}, ] +pytz = [ + {file = "pytz-2022.2.1-py2.py3-none-any.whl", hash = "sha256:220f481bdafa09c3955dfbdddb7b57780e9a94f5127e35456a48589b9e0c0197"}, + {file = "pytz-2022.2.1.tar.gz", hash = "sha256:cea221417204f2d1a2aa03ddae3e867921971d0d76f14d87abb4414415bbdcf5"}, +] +pytz-deprecation-shim = [ + {file = "pytz_deprecation_shim-0.1.0.post0-py2.py3-none-any.whl", hash = "sha256:8314c9692a636c8eb3bda879b9f119e350e93223ae83e70e80c31675a0fdc1a6"}, + {file = "pytz_deprecation_shim-0.1.0.post0.tar.gz", hash = "sha256:af097bae1b616dde5c5744441e2ddc69e74dfdcb0c263129610d85b87445a59d"}, +] requests = [ {file = "requests-2.28.1-py3-none-any.whl", hash = "sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349"}, {file = "requests-2.28.1.tar.gz", hash = "sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983"}, @@ -547,6 +629,14 @@ typing-extensions = [ {file = "typing_extensions-4.3.0-py3-none-any.whl", hash = "sha256:25642c956049920a5aa49edcdd6ab1e06d7e5d467fc00e0506c44ac86fbfca02"}, {file = "typing_extensions-4.3.0.tar.gz", hash = "sha256:e6d2677a32f47fc7eb2795db1dd15c1f34eff616bcaf2cfb5e997f854fa1c4a6"}, ] +tzdata = [ + {file = "tzdata-2022.2-py2.py3-none-any.whl", hash = "sha256:c3119520447d68ef3eb8187a55a4f44fa455f30eb1b4238fa5691ba094f2b05b"}, + {file = "tzdata-2022.2.tar.gz", hash = "sha256:21f4f0d7241572efa7f7a4fdabb052e61b55dc48274e6842697ccdf5253e5451"}, +] +tzlocal = [ + {file = "tzlocal-4.2-py3-none-any.whl", hash = "sha256:89885494684c929d9191c57aa27502afc87a579be5cdd3225c77c463ea043745"}, + {file = "tzlocal-4.2.tar.gz", hash = "sha256:ee5842fa3a795f023514ac2d801c4a81d1743bbe642e3940143326b3a00addd7"}, +] urllib3 = [ {file = "urllib3-1.26.12-py2.py3-none-any.whl", hash = "sha256:b930dd878d5a8afb066a637fbb35144fe7901e3b209d1cd4f524bd0e9deee997"}, {file = "urllib3-1.26.12.tar.gz", hash = "sha256:3fa96cf423e6987997fc326ae8df396db2a8b7c667747d47ddd8ecba91f4a74e"}, @@ -555,6 +645,9 @@ uvicorn = [ {file = "uvicorn-0.18.3-py3-none-any.whl", hash = "sha256:0abd429ebb41e604ed8d2be6c60530de3408f250e8d2d84967d85ba9e86fe3af"}, {file = "uvicorn-0.18.3.tar.gz", hash = "sha256:9a66e7c42a2a95222f76ec24a4b754c158261c4696e683b9dadc72b590e0311b"}, ] +vobject = [ + {file = "vobject-0.9.6.1.tar.gz", hash = "sha256:96512aec74b90abb71f6b53898dd7fe47300cc940104c4f79148f0671f790101"}, +] webdavclient3 = [ {file = "webdavclient3-3.14.5.tar.gz", hash = "sha256:6072f9a583059f8ff313f8544d415b4191fc89bdf6230259b0527b706ab1837b"}, ] diff --git a/api/pyproject.toml b/api/pyproject.toml index 29a6221..278093a 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -13,6 +13,7 @@ pydantic = {extras = ["dotenv"], version = "^1.9.2"} python = "^3.9" uvicorn = "^0.18.3" webdavclient3 = "3.14.5" +caldav = "^0.9.1" [tool.poetry.dev-dependencies] # pytest = "^5.2"