From 371577c001268d46afc23b8752aa62aecb458d11 Mon Sep 17 00:00:00 2001 From: Night-stars-1 <99261160+Night-stars-1@users.noreply.github.com> Date: Tue, 14 Feb 2023 17:21:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A8=E9=80=81=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=20(#82)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复无法获取成长值的问题 更改成长值获取接口 * 修复无法获取成长值的问题 更改成长值获取接口 * 改用正则获取成长值 * 推送配置说明 * 更新推送 * 更新推送 * Update config.yaml * Update config.yaml * Update requirements.txt * Update config.yaml * format the file * 提升版本号 * 提升版本号 * 提升版本号 --------- Co-authored-by: 0-8-4 --- README.md | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ config.yaml | 10 ++++++- miuitask.py | 7 +++-- requirements.txt | 3 +- utils/utils.py | 30 +++++++++++++++++-- 5 files changed, 118 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4d0c21b..ed26950 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,82 @@ ⚠ 请注意,修改配置文件开启完成限时专题任务后 MIUI Task 不会检测当前是否可完成限时专题任务而会直接发送请求,根据社区相关规则,启用完成限时专题任务、拔萝卜及签到等可能存在风险。您需要自行承担使用本脚本的后果 +### **配置推送**: +推送基于[onepush](https://github.com/y1ndan/onepush) +- 推送名称 / notifier: bark + + 参数大全 / params: + {'required': ['key'], 'optional': ['title', 'sound', 'isarchive', 'icon', 'group', 'url', 'copy', 'autocopy']} + +- 推送名称 / notifier: custom + + 参数大全 / params: + {'required': ['url'], 'optional': ['method', 'datatype', 'data']} + +- 推送名称 / notifier: dingtalk + + 参数大全 / params: + {'required': ['token'], 'optional': ['title', 'secret', 'markdown']} + +- 推送名称 / notifier: discord + + 参数大全 / params: + {'required': ['webhook'], 'optional': ['title', 'username', 'avatar_url', 'color']} + +- 推送名称 / notifier: pushplus + + 参数大全 / params: + {'required': ['token'], 'optional': ['title', 'topic', 'markdown']} + +- 推送名称 / notifier: qmsg + + 参数大全 / params: + {'required': ['key'], 'optional': ['title', 'mode', 'qq']} + +- 推送名称 / notifier: serverchan + + 参数大全 / params: + {'required': ['sckey', 'title'], 'optional': []} + +- 推送名称 / notifier: serverchanturbo + + 参数大全 / params: + {'required': ['sctkey', 'title'], 'optional': ['channel', 'openid']} + +- 推送名称 / notifier: telegram + + 参数大全 / params: + {'required': ['token', 'userid'], 'optional': ['title', 'api_url']} + +- 推送名称 / notifier: wechatworkapp + + 参数大全 / params: + {'required': ['corpid', 'corpsecret', 'agentid'], 'optional': ['title', 'touser', 'markdown']} + +- 推送名称 / notifier: wechatworkbot + + 参数大全 / params: + {'required': ['key'], 'optional': ['title', 'markdown']} +* **required为必填参数,optional为选填参数** + +配置参考: +```yaml +ONEPUSH: + notifier: telegram + params: + title: + markdown: false + token: 123456789:XXXXXXXXXXXXXXXXXXXXXXXX + userid: 114514 +``` +```yaml +ONEPUSH: + notifier: pushplus + params: + title: + token: XXXXXXXXXXXXXXXXXXXXXXXX + markdown: false +``` #### **其他**: * 在使用本脚本时请临时关闭网络代理工具及广告拦截程序 * 在服务器上使用前建议先使用服务器IP登录 `https://account.xiaomi.com` diff --git a/config.yaml b/config.yaml index 41c9b87..84da557 100644 --- a/config.yaml +++ b/config.yaml @@ -21,7 +21,15 @@ accounts: # carrot-pull: false # check-in: false # browse-specialpage: false +ONEPUSH: + notifier: telegram + params: + title: + markdown: false + token: + userid: + logging: false # 归档日志到本地文件 -version: v1.5.2 +version: v1.5.3 # config 文件版本号,debug用 diff --git a/miuitask.py b/miuitask.py index c28dc3e..04732be 100644 --- a/miuitask.py +++ b/miuitask.py @@ -9,7 +9,7 @@ from urllib import request from http import cookiejar from utils.utils import system_info, get_config, w_log, s_log, check_config, format_config, random_sleep, \ - sleep_ten_sec_more + sleep_ten_sec_more, notify_me class MIUITask: @@ -432,7 +432,7 @@ def start(miui_task: MIUITask, check_in: bool, carrot_pull: bool, browse_special def main(): - w_log("MIUI-AUTO-TASK v1.5.2") + w_log("MIUI-AUTO-TASK v1.5.3") w_log('---------- 系统信息 -------------') system_info() w_log('---------- 项目信息 -------------') @@ -447,7 +447,7 @@ def main(): exit(1) else: config = format_config(config) - + for i in config.get('accounts'): w_log('---------- EXECUTING -------------') start( @@ -456,6 +456,7 @@ def main(): ) time.sleep(5) s_log(config.get('logging')) + notify_me() def main_handler(event, context): diff --git a/requirements.txt b/requirements.txt index db0c977..ed5c17d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ requests>=2.25.1 python-dotenv>=0.19.2 -PyYAML>=6.0 \ No newline at end of file +PyYAML>=6.0 +onepush diff --git a/utils/utils.py b/utils/utils.py index ec36e3d..ef632bb 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -2,13 +2,17 @@ import os import random import time import platform -import dotenv, yaml +import dotenv +import yaml from hashlib import md5 +from onepush import notify from urllib.request import getproxies logs = '' -CONFIG_VERSION_REQUIRE: str = 'v1.5.2' +message = '' +config = {'account': []} +CONFIG_VERSION_REQUIRE: str = 'v1.5.3' def md5_crypto(passwd: str) -> str: @@ -32,7 +36,7 @@ def system_info(): def get_config() -> dict: - config = {'account': []} + global config config_path_legacy = dotenv.find_dotenv(filename='config.env') config_path_yaml = dotenv.find_dotenv(filename='config.yaml') @@ -89,8 +93,10 @@ def get_config() -> dict: def w_log(text): global logs + global message now_localtime = time.strftime("%H:%M:%S", time.localtime()) logs += now_localtime + ' | ' + str(text) + '\n' + message += str(text) + '\n' print(now_localtime + ' | ' + str(text)) @@ -145,3 +151,21 @@ def random_sleep(): def sleep_ten_sec_more(): time.sleep(random.randint(10, 12)) + + +def notify_me(content=None): + """ + 默认推送日志 + """ + global message + global config + if not content: + content = message + notifier = config.get('ONEPUSH', {}).get('notifier', '') + params = config.get('ONEPUSH', {}).get('params', '') + if not notifier or not params: + s_log('未配置推送或未正确配置推送') + return + if not config.get('ONEPUSH', {}).get('title', ''): + config['ONEPUSH']['title'] = '' + return notify(notifier, content=content, **params)