From 140784c4e034ed94aeece0aa164c3a82ccf0a371 Mon Sep 17 00:00:00 2001 From: lucasheld Date: Thu, 7 Jul 2022 22:17:47 +0200 Subject: [PATCH] prepare pypi release and fix add monitor --- .gitignore | 1 + .../build_params_map_notification_provider.py | 2 +- setup.py | 54 ++++++++++-- .../__init__.py | 1 + uptime_kuma_api/__version__.py | 5 ++ {uptimekumaapi => uptime_kuma_api}/api.py | 83 ++++++++++--------- .../auth_method.py | 0 .../converter.py | 2 +- .../exceptions.py | 0 .../incident_style.py | 0 .../monitor_type.py | 0 .../notification_providers.py | 0 .../proxy_protocol.py | 0 13 files changed, 96 insertions(+), 52 deletions(-) rename {uptimekumaapi => uptime_kuma_api}/__init__.py (88%) create mode 100644 uptime_kuma_api/__version__.py rename {uptimekumaapi => uptime_kuma_api}/api.py (92%) rename {uptimekumaapi => uptime_kuma_api}/auth_method.py (100%) rename {uptimekumaapi => uptime_kuma_api}/converter.py (98%) rename {uptimekumaapi => uptime_kuma_api}/exceptions.py (100%) rename {uptimekumaapi => uptime_kuma_api}/incident_style.py (100%) rename {uptimekumaapi => uptime_kuma_api}/monitor_type.py (100%) rename {uptimekumaapi => uptime_kuma_api}/notification_providers.py (100%) rename {uptimekumaapi => uptime_kuma_api}/proxy_protocol.py (100%) diff --git a/.gitignore b/.gitignore index 2622dbe..36bb7dd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ venv .envrc __pycache__ *.egg-info +dist diff --git a/datacollection/build_params_map_notification_provider.py b/datacollection/build_params_map_notification_provider.py index 6ed3b23..e7c3486 100644 --- a/datacollection/build_params_map_notification_provider.py +++ b/datacollection/build_params_map_notification_provider.py @@ -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(): diff --git a/setup.py b/setup.py index 1cd7708..f58ca8c 100644 --- a/setup.py +++ b/setup.py @@ -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" + ] ) diff --git a/uptimekumaapi/__init__.py b/uptime_kuma_api/__init__.py similarity index 88% rename from uptimekumaapi/__init__.py rename to uptime_kuma_api/__init__.py index 2d94c86..2189719 100644 --- a/uptimekumaapi/__init__.py +++ b/uptime_kuma_api/__init__.py @@ -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 diff --git a/uptime_kuma_api/__version__.py b/uptime_kuma_api/__version__.py new file mode 100644 index 0000000..72ecfec --- /dev/null +++ b/uptime_kuma_api/__version__.py @@ -0,0 +1,5 @@ +__title__ = "uptime_kuma_api" +__version__ = "0.0.3" +__author__ = "Lucas Held" +# __license__ = "" +__copyright__ = "Copyright 2022 Lucas Held" diff --git a/uptimekumaapi/api.py b/uptime_kuma_api/api.py similarity index 92% rename from uptimekumaapi/api.py rename to uptime_kuma_api/api.py index 724e06c..2394b1d 100644 --- a/uptimekumaapi/api.py +++ b/uptime_kuma_api/api.py @@ -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 diff --git a/uptimekumaapi/auth_method.py b/uptime_kuma_api/auth_method.py similarity index 100% rename from uptimekumaapi/auth_method.py rename to uptime_kuma_api/auth_method.py diff --git a/uptimekumaapi/converter.py b/uptime_kuma_api/converter.py similarity index 98% rename from uptimekumaapi/converter.py rename to uptime_kuma_api/converter.py index a21f255..a666c38 100644 --- a/uptimekumaapi/converter.py +++ b/uptime_kuma_api/converter.py @@ -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 diff --git a/uptimekumaapi/exceptions.py b/uptime_kuma_api/exceptions.py similarity index 100% rename from uptimekumaapi/exceptions.py rename to uptime_kuma_api/exceptions.py diff --git a/uptimekumaapi/incident_style.py b/uptime_kuma_api/incident_style.py similarity index 100% rename from uptimekumaapi/incident_style.py rename to uptime_kuma_api/incident_style.py diff --git a/uptimekumaapi/monitor_type.py b/uptime_kuma_api/monitor_type.py similarity index 100% rename from uptimekumaapi/monitor_type.py rename to uptime_kuma_api/monitor_type.py diff --git a/uptimekumaapi/notification_providers.py b/uptime_kuma_api/notification_providers.py similarity index 100% rename from uptimekumaapi/notification_providers.py rename to uptime_kuma_api/notification_providers.py diff --git a/uptimekumaapi/proxy_protocol.py b/uptime_kuma_api/proxy_protocol.py similarity index 100% rename from uptimekumaapi/proxy_protocol.py rename to uptime_kuma_api/proxy_protocol.py