|
|
@@ -5,10 +5,12 @@
|
|
|
import os
|
|
|
import sys
|
|
|
import time
|
|
|
-from datetime import datetime
|
|
|
+import json
|
|
|
from bs4 import BeautifulSoup
|
|
|
import httpx
|
|
|
|
|
|
+from utils.gotify import GotifyNotifier
|
|
|
+
|
|
|
sys.path.append(os.path.join(os.path.abspath(__file__).split('AutoInfo')[0] + 'AutoInfo'))
|
|
|
SUB_PROJECT_NAME = "获取天气预报"
|
|
|
PROJECT_PATH = os.path.join(os.path.abspath(__file__).split('AutoInfo')[0] + 'AutoInfo')
|
|
|
@@ -52,61 +54,8 @@ class Weather():
|
|
|
print('天气预报数据已获取')
|
|
|
|
|
|
|
|
|
-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)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
- # W = Weather().main()
|
|
|
- print(PROJECT_PATH)
|
|
|
+ W = Weather().main()
|
|
|
|