mirror of
https://github.com/TDSCDMAA/AutoMihoyoBBS.git
synced 2026-06-06 12:23:06 +08:00
内置推送测试
This commit is contained in:
parent
09ebc1c08f
commit
92c03aeb34
8
config/push.ini
Normal file
8
config/push.ini
Normal 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
8
config/push.ini.example
Normal 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 #推送给谁
|
||||
6
main.py
6
main.py
@ -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
|
||||
|
||||
@ -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
60
push.py
Normal 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
|
||||
Loading…
Reference in New Issue
Block a user