-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c44db1
commit 326da72
Showing
4 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters