You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
manual-tools/utils/utils_send_gotify.py

58 lines
1.7 KiB

# -*- coding: utf-8 -*-
import httpx
class GotifyNotifier:
def __init__(self, title, message, token_name=''):
self.gotify_url = 'https://gotify.erhe.top'
self.app_token = self.match_token_name(token_name)
self.title = title
self.message = message
def match_token_name(self, name):
token_name_dict = {
'base': 'A8EVb0Cmxnb2vfk',
'coin': 'AgfOJESqDKftBTQ',
'dlt': 'A3bqt9Dlbs.fPUb',
'AirdropTasksNews': 'Aoe0VKt-kkZnm8d',
'weather': 'A9KF--mx_12PjSu',
'news': 'AT2QGp_vyCX4akW',
'CheckAndRemind': 'Aw7XKE2Ppk7Dgwk',
'test': 'A0Xg6ZE5946iBYg',
}
token = token_name_dict.get(name)
if token:
return token
else:
return token_name_dict['base']
def send_message(self):
# 构建POST请求的headers
headers = {
'Content-Type': 'application/json'
}
# 构建POST请求的body
body = {
'title': self.title,
'message': self.message
}
# 发送POST请求
with httpx.Client() as client:
response = client.post(
url=f"{self.gotify_url}/message?token={self.app_token}",
headers=headers,
json=body
)
# 或者可以使用 curl
# curl -k "https://gotify.erhe.top/message?token=A0Xg6ZE5946iBYg" -F "title=测试发送信息" -F "message=假装有信息,测试发送" -F "priority=5"
# 检查响应状态码
if response.status_code == 200:
print('Gotify Message sent successfully!')
else:
print('Failed to send message:', response.text)