Skip to content

Commit

Permalink
新增 Ntfy 消息推送
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyMerlin committed Jul 8, 2024
1 parent 72072db commit aca4c5f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
26 changes: 26 additions & 0 deletions ANotify/Nntfy.py
Original file line number Diff line number Diff line change
@@ -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"))
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='anotify',
version='0.1.8',
version='0.1.9',
packages=find_packages(),
install_requires=[
'requests>=2.15.1',
Expand Down

0 comments on commit aca4c5f

Please # to comment.