Skip to content

Commit

Permalink
新增 Gotify 消息推送
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyMerlin committed Jul 8, 2024
1 parent 8c44db1 commit 326da72
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
39 changes: 39 additions & 0 deletions ANotify/Ngotify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import requests
from enum import Enum

class MessageType(Enum):
plaintext = 'text/plain' # 默认模板,纯文本展
markdown = 'text/markdown' # 内容基于markdown格式展示

class GotifyNotify:
def __init__(self, server_url, token):
self.server_url = server_url
self.token = token

def send_msg(self, title, content, message_type=MessageType.plaintext):
url = self.server_url.rstrip('/') + "/message"

querystring = {"token":self.token}

payload = {
"extras": {
"client::display": {
"contentType": message_type.value
}
},
"message": content,
"priority": 5,
"title": title
}
headers = {"content-type": "application/json"}

response = requests.post(url, json=payload, headers=headers, params=querystring)

return response.json()


if __name__ == "__main__":
TOKEN = ""
URL = ""
gotify = GotifyNotify(URL,TOKEN)
print(gotify.send_msg("title", "content"))
Binary file added ANotify/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ dingtalk_webhook = Ndingtalk.DingtalkWebhookNotify(WEB_HOOK)
dingtalk_webhook.send_msg("Hello World!")
```

### Gotify
[官网](https://gotify.net/docs/)
```python
from ANotify import Ngotify
TOKEN = ""
SERVER_URL = ""
gotify = Ngotify.GotifyNotify(TOKEN)
gotify.send_msg("title", "content")
gotify.send_msg("title", "**content**\n- No.1\n- No.2", Ngotify.MessageType.markdown)

### 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.7',
version='0.1.8',
packages=find_packages(),
install_requires=[
'requests>=2.15.1',
Expand Down

0 comments on commit 326da72

Please sign in to comment.