Skip to content
Merged
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
4 changes: 4 additions & 0 deletions pythonkuma/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
"""Python API wrapper for Uptime Kuma."""

from .exceptions import (
UpdateException,
UptimeKumaAuthenticationException,
UptimeKumaConnectionException,
UptimeKumaException,
)
from .models import MonitorStatus, MonitorType, UptimeKumaMonitor, UptimeKumaVersion
from .update import UpdateChecker
from .uptimekuma import UptimeKuma

__version__ = "0.2.0"

__all__ = [
"MonitorStatus",
"MonitorType",
"UpdateChecker",
"UpdateException",
"UptimeKuma",
"UptimeKumaAuthenticationException",
"UptimeKumaConnectionException",
Expand Down
4 changes: 4 additions & 0 deletions pythonkuma/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ class UptimeKumaConnectionException(UptimeKumaException):

class UptimeKumaAuthenticationException(UptimeKumaException):
"""Uptime Kuma authentication exception."""


class UpdateException(Exception):
"""Exception raised for errors fetching latest release from github."""
52 changes: 52 additions & 0 deletions pythonkuma/update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Check for latest Uptime Kuma release."""

from __future__ import annotations

from dataclasses import dataclass

from aiohttp import ClientError, ClientSession
from yarl import URL

from .exceptions import UpdateException

BASE_URL = URL("https://api.github.com/repos/louislam/uptime-kuma")


@dataclass(kw_only=True)
class LatestRelease:
"""Latest release data."""

tag_name: str
name: str
html_url: str
body: str


class UpdateChecker:
"""Check for Uptime Kuma updates."""

def __init__(
self,
session: ClientSession,
) -> None:
"""Initialize Uptime Kuma release checker."""
self._session = session

async def latest_release(self) -> LatestRelease:
"""Fetch latest IronOS release."""
url = BASE_URL / "releases/latest"
try:
async with self._session.get(url) as response:
data = await response.json()
return LatestRelease(
tag_name=data["tag_name"],
name=data["name"],
html_url=data["html_url"],
body=data["body"],
)
except ClientError as e:
msg = "Failed to fetch latest Uptime Kuma release from Github"
raise UpdateException(msg) from e
except KeyError as e:
msg = "Failed to parse latest Uptime Kuma release from Github response"
raise UpdateException(msg) from e
Loading