prepare pypi release and fix add monitor

This commit is contained in:
lucasheld 2022-07-07 22:17:47 +02:00
parent b87a1bdaf0
commit 140784c4e0
13 changed files with 96 additions and 52 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@ venv
.envrc
__pycache__
*.egg-info
dist

View file

@ -1,7 +1,7 @@
import re
import os
from uptimekumaapi import notification_provider_options
from uptime_kuma_api import notification_provider_options
def build_notification_provider_map():

View file

@ -1,12 +1,48 @@
from setuptools import setup, find_packages
from setuptools import setup
from codecs import open
import os
import sys
# "setup.py publish" shortcut.
if sys.argv[-1] == "publish":
os.system("rm dist/*")
os.system("python setup.py sdist")
os.system("twine upload --repository-url https://test.pypi.org/legacy/ dist/*")
sys.exit()
info = {}
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, "uptime_kuma_api", "__version__.py"), "r", "utf-8") as f:
exec(f.read(), info)
setup(
name="uptimekumaapi",
version="0.0.0",
packages=find_packages(),
install_requires=[
"python-socketio==5.6.0",
"requests==2.28.1",
"websocket-client==1.3.3",
],
name=info["__title__"],
version=info["__version__"],
description="A python wrapper for the Uptime Kuma WebSocket API",
url="https://github.com/lucasheld/uptime-kuma-api",
author=info["__author__"],
author_email="lucasheld@hotmail.de",
# license=info["__license__"],
packages=["uptime_kuma_api"],
python_requires=">=3.6, <4",
install_requires=["python-socketio", "requests", "websocket-client"],
classifiers=[
"Development Status :: 1 - Planning",
"Environment :: Web Environment",
"Intended Audience :: Developers",
# "License :: OSI Approved :: ",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Software Development :: Libraries"
]
)

View file

@ -1,3 +1,4 @@
from .__version__ import __title__, __version__, __author__, __copyright__
from .auth_method import AuthMethod
from .monitor_type import MonitorType
from .notification_providers import NotificationType, notification_provider_options

View file

@ -0,0 +1,5 @@
__title__ = "uptime_kuma_api"
__version__ = "0.0.3"
__author__ = "Lucas Held"
# __license__ = ""
__copyright__ = "Copyright 2022 Lucas Held"

View file

@ -14,7 +14,7 @@ from . import convert_from_socket, convert_to_socket, params_map_monitor, params
from . import UptimeKumaException
def int_to_bool(data: list[dict] | dict, keys):
def int_to_bool(data, keys):
if type(data) == list:
for d in data:
int_to_bool(d, keys)
@ -102,55 +102,55 @@ def _build_monitor_data(
"keyword": keyword,
})
if type_ in [MonitorType.HTTP, MonitorType.KEYWORD]:
# if type_ in [MonitorType.HTTP, MonitorType.KEYWORD]:
data.update({
"url": url,
"certificate_expiry_notification": certificate_expiry_notification,
"ignore_tls_error": ignore_tls_error,
"max_redirects": max_redirects,
"accepted_status_codes": accepted_status_codes,
"proxy_id": proxy_id,
"http_method": http_method,
"http_body": http_body,
"http_headers": http_headers,
"auth_method": auth_method,
})
if auth_method in [AuthMethod.HTTP_BASIC, AuthMethod.NTLM]:
data.update({
"url": url,
"certificate_expiry_notification": certificate_expiry_notification,
"ignore_tls_error": ignore_tls_error,
"max_redirects": max_redirects,
"accepted_status_codes": accepted_status_codes,
"proxy_id": proxy_id,
"http_method": http_method,
"http_body": http_body,
"http_headers": http_headers,
"auth_method": auth_method,
"auth_user": auth_user,
"auth_pass": auth_pass,
})
if auth_method in [AuthMethod.HTTP_BASIC, AuthMethod.NTLM]:
data.update({
"auth_user": auth_user,
"auth_pass": auth_pass,
})
if auth_method == AuthMethod.NTLM:
data.update({
"auth_domain": auth_domain,
"auth_workstation": auth_workstation,
})
if type_ in [MonitorType.DNS, MonitorType.PING, MonitorType.STEAM, MonitorType.MQTT]:
if auth_method == AuthMethod.NTLM:
data.update({
"hostname": hostname,
"auth_domain": auth_domain,
"auth_workstation": auth_workstation,
})
# if type_ in [MonitorType.DNS, MonitorType.PING, MonitorType.STEAM, MonitorType.MQTT]:
data.update({
"hostname": hostname,
})
if type_ in [MonitorType.DNS, MonitorType.STEAM, MonitorType.MQTT]:
data.update({
"port": port,
})
if type_ == MonitorType.DNS:
data.update({
"dns_resolve_server": dns_resolve_server,
"dns_resolve_type": dns_resolve_type,
})
# if type_ == MonitorType.DNS:
data.update({
"dns_resolve_server": dns_resolve_server,
"dns_resolve_type": dns_resolve_type,
})
if type_ == MonitorType.MQTT:
data.update({
"mqtt_username": mqtt_username,
"mqtt_password": mqtt_password,
"mqtt_topic": mqtt_topic,
"mqtt_success_message": mqtt_success_message,
})
# if type_ == MonitorType.MQTT:
data.update({
"mqtt_username": mqtt_username,
"mqtt_password": mqtt_password,
"mqtt_topic": mqtt_topic,
"mqtt_success_message": mqtt_success_message,
})
if type_ == MonitorType.SQLSERVER:
data.update({
@ -286,9 +286,10 @@ class UptimeKumaApi(object):
def _call(self, event, data=None):
r = self.sio.call(event, data)
if type(r) == dict and not r["ok"]:
raise UptimeKumaException(r["msg"])
r.pop("ok")
if type(r) == dict and "ok" in r:
if not r["ok"]:
raise UptimeKumaException(r["msg"])
r.pop("ok")
return r
# event handlers

View file

@ -207,7 +207,7 @@ params_map_settings = {
}
def _convert_to_from_socket(params_map: dict[str, str], params: list[dict] | dict | str, to_socket=False):
def _convert_to_from_socket(params_map: dict[str, str], params, to_socket=False):
if type(params) == list:
out = []
params_list = params