内置推送测试

This commit is contained in:
Womsxd 2022-01-09 17:31:44 +08:00
parent 09ebc1c08f
commit 92c03aeb34
No known key found for this signature in database
GPG Key ID: 0FE76418EE689B68
5 changed files with 84 additions and 3 deletions

8
config/push.ini Normal file
View File

@ -0,0 +1,8 @@
[setting]
enable=false
push_server=cqhttp #共有 cqhttp ftqq(sever酱) Pushplus
push_token=123456 #server酱和pushplus的推送token
[cqhttp]
cqhttp_url=http://127.0.0.1:5000/send_private_msg #cqhttp的服务端地址
cqhttp_qq=10001 #推送给谁

8
config/push.ini.example Normal file
View File

@ -0,0 +1,8 @@
[setting]
enable=true
push_server=cqhttp #共有 cqhttp ftqq(sever酱) Pushplus
push_token=123456 #server酱和pushplus的推送token
[cqhttp]
cqhttp_url=http://127.0.0.1:5000/send_private_msg #cqhttp的服务端地址
cqhttp_qq=10001 #推送给谁

View File

@ -1,6 +1,6 @@
import time
import push
import login
import tools
import config
import random
import genshin
@ -83,7 +83,9 @@ def main():
if __name__ == "__main__":
try:
main()
status_code = main()
except CookieError:
status_code = 0
log.error("账号Cookie有问题")
push.push(status_code, "脚本已执行")
pass

View File

@ -2,6 +2,7 @@ import os
import sys
import main
import time
import push
import config
import random
import setting
@ -50,7 +51,9 @@ def main_multi(autorun: bool):
log.info(f"{i}执行完毕")
time.sleep(random.randint(3, 10))
print("")
log.info(f'脚本执行完毕,共执行{len(config_list)}个配置文件,成功{len(results["ok"])}个,没执行{results["close"]}个,失败{len(results["error"])}')
push_message = f'脚本执行完毕,共执行{len(config_list)}个配置文件,成功{len(results["ok"])}个,没执行{results["close"]}个,失败{len(results["error"])}'
log.info(push_message)
push.push(0,push_message)
if __name__ == "__main__":

60
push.py Normal file
View File

@ -0,0 +1,60 @@
import os
from request import http
from configparser import ConfigParser
cfg = ConfigParser()
def load_config():
config_path = os.path.dirname(os.path.realpath(__file__)) + "/push.ini"
cfg.read(config_path)
def title(status):
if status == 0:
return "「米游社脚本」执行成功!"
else:
return "「米游社脚本」执行失败!"
def ftqq(status, push_message):
http.post(
url="https://sctapi.ftqq.com/{}.send".format(cfg.get('setting', 'push_token')),
data={
"title": title(status),
"desp": push_message
}
)
def pushplus(status, push_message):
http.post(
url="http://www.pushplus.plus/send",
data={
"token": cfg.get('setting', 'push_token'),
"title": title(status),
"content": push_message
}
)
def cq_http(status, push_message):
http.post(
url=cfg.get('cqhttp', 'cqhttp_url'),
json={
"user_id": cfg.getint('cqhttp', 'cqhttp_qq'),
"message": title(status) + "\r\n" + push_message
}
)
def push(status, push_message):
load_config()
if cfg.getboolean('setting', 'enable'):
if cfg.get('setting', 'push_server') == "cq_http":
cq_http(status, push_message)
elif cfg.get('setting', 'push_server') == "ftqq":
ftqq(status, push_message)
elif cfg.get('setting', 'push_server') == "pushplus":
pushplus(status, push_message)
return 0