From aca4c5f0dcd14cd63080ad69c020a1985ab43723 Mon Sep 17 00:00:00 2001 From: HuYe Date: Mon, 8 Jul 2024 16:45:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20Ntfy=20=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ANotify/Nntfy.py | 26 ++++++++++++++++++++++++++ README.md | 10 ++++++++++ setup.py | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 ANotify/Nntfy.py diff --git a/ANotify/Nntfy.py b/ANotify/Nntfy.py new file mode 100644 index 0000000..401b21d --- /dev/null +++ b/ANotify/Nntfy.py @@ -0,0 +1,26 @@ +import requests +from enum import Enum + +class MessageType(Enum): + plaintext = 'text/plain' # 默认模板,纯文本展 + markdown = 'text/markdown' # 内容基于markdown格式展示 + +class NtfyNotify: + def __init__(self, topic, server_url = "https://ntfy.sh"): + self.server_url = server_url + self.topic = topic + + def send_msg(self, title, msg): + url = self.server_url.rstrip('/') + "/" + self.topic + response = requests.post(url, + data=msg.encode("utf-8"), + headers={ "Title": title }) + + return response.json() + + +if __name__ == "__main__": + TOPIC = "" + URL = "" + ntfy = NtfyNotify(TOPIC, URL) + print(ntfy.send_msg("title","msg")) \ No newline at end of file diff --git a/README.md b/README.md index 478c68b..cb17ad3 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,16 @@ gotify.send_msg("title", "content") gotify.send_msg("title", "**content**\n- No.1\n- No.2", Ngotify.MessageType.markdown) ``` +### Ntfy +[官网](https://docs.ntfy.sh/publish/) +```python +from ANotify import Nntfy +TOPIC = "" +URL = "" +ntfy = Nntfy.NtfyNotify(TOPIC, URL) +ntfy.send_msg("title", "content") +``` + ### AnPush [官网](https://anpush.com/) ```python diff --git a/setup.py b/setup.py index 2b54a1d..deaaf81 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='anotify', - version='0.1.8', + version='0.1.9', packages=find_packages(), install_requires=[ 'requests>=2.15.1',