Skip to content

Commit

Permalink
优化pushplus推送逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyJiangWJ committed Jun 6, 2023
1 parent fa94e03 commit c373cc1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"MAX_STEP": "25000",
"PUSH_PLUS_TOKEN": "",
"PUSH_PLUS_HOUR": "",
"PUSH_PLUS_MAX": "30",
"SLEEP_GAP": "5",
"USE_CONCURRENT": "False"
}
Expand All @@ -74,8 +75,9 @@
| MAX_STEP | 最大步数,最大步数和最小步数随机范围随着时间线性增加,北京时间22点达到最大值 |
| PUSH_PLUS_TOKEN | 推送加的个人token,申请地址[pushplus](https://www.pushplus.plus/push1.html),工作流执行完成后推送每个账号的执行状态信息,如没有则不要填写 |
| PUSH_PLUS_HOUR | 限制只在某个整点进行pushplus的推送,值为整数,比如设置21,则只在北京时间21点XX分执行时才进行pushplus的消息推送。如不设置或值非数字则每次执行后都会进行推送 |
| PUSH_PLUS_MAX | 设置pushplus最大推送账号详情数,默认为30,超过30个账号将只推送概要信息:多少个成功多少个失败。因为数量太多会导致内容过长无法推送。具体最大值请自行调试 |
| SLEEP_GAP | 多账号执行间隔,单位秒,如果账号比较多可以设置的短一点,默认为5秒 |
| USE_CONCURRENT | 是否使用多线程,实验性功能,未测试是否有效。账号多的可以试试,将它设置为True即可,启用后 `SLEEP_GAP` 将不再生效 |
| USE_CONCURRENT | 是否使用多线程,实验性功能,未测试是否有效。账号多的可以试试,将它设置为True即可,启用后 `SLEEP_GAP` 将不再生效 |

### 三、多账户设置(如用不上请忽略)

Expand Down
39 changes: 28 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,25 @@ def login_and_post_step(self, min_step, max_step):


# 启动主函数
def push_to_push_plus(exec_results):
def push_to_push_plus(exec_results, summary):
# 判断是否需要pushplus推送
if PUSH_PLUS_TOKEN is not None and PUSH_PLUS_TOKEN != '' and PUSH_PLUS_TOKEN != 'NO':
if PUSH_PLUS_HOUR is not None and PUSH_PLUS_HOUR.isdigit():
if time_bj.hour != int(PUSH_PLUS_HOUR):
print(f"当前设置push_plus推送整点为:{PUSH_PLUS_HOUR}, 当前整点为:{time_bj.hour},跳过推送")
return
html = '<ul>'
for exec_result in exec_results:
success = exec_result['success']
if success is not None and success is True:
html += f'<li><span>账号:{exec_result["user"]}</span>刷步数成功,接口返回:{exec_result["msg"]}</li>'
else:
html += f'<li><span>账号:{exec_result["user"]}</span>刷步数失败,失败原因:{exec_result["msg"]}</li>'
html += '</ul>'
html = f'<div>{summary}</div>'
if len(exec_results) >= PUSH_PLUS_MAX:
html += '<div>账号数量过多,详细情况请前往github actions中查看</div>'
else:
html += '<ul>'
for exec_result in exec_results:
success = exec_result['success']
if success is not None and success is True:
html += f'<li><span>账号:{exec_result["user"]}</span>刷步数成功,接口返回:{exec_result["msg"]}</li>'
else:
html += f'<li><span>账号:{exec_result["user"]}</span>刷步数失败,失败原因:{exec_result["msg"]}</li>'
html += '</ul>'
push_plus(f"{format_now()} 刷步数通知", html)


Expand Down Expand Up @@ -290,7 +294,13 @@ def execute():
# 每个账号之间间隔一定时间请求一次,避免接口请求过于频繁导致异常
time.sleep(sleep_seconds)

push_to_push_plus(exec_results)
success_count = 0
for result in exec_results:
if result['success'] is True:
success_count += 1
summary = f"\n执行账号总数{total},成功:{success_count},失败:{total - success_count}"
print(summary)
push_to_push_plus(exec_results, summary)
else:
print(f"账号数长度[{len(user_list)}]和密码数长度[{len(passwd_list)}]不匹配,跳过执行")
exit(1)
Expand All @@ -304,9 +314,16 @@ def execute():
exit(1)
else:
# region 初始化参数
config = dict(json.loads(os.environ.get("CONFIG")))
config = dict()
try:
config = dict(json.loads(os.environ.get("CONFIG")))
except:
print("CONFIG格式不正确,请检查Secret配置,请严格按照JSON格式:使用双引号包裹字段和值,逗号不能多也不能少")
traceback.print_exc()
exit(1)
PUSH_PLUS_TOKEN = config.get('PUSH_PLUS_TOKEN')
PUSH_PLUS_HOUR = config.get('PUSH_PLUS_HOUR')
PUSH_PLUS_MAX = get_int_value_default(config, 'PUSH_PLUS_MAX', 30)
sleep_seconds = config.get('SLEEP_GAP')
if sleep_seconds is None or sleep_seconds == '':
sleep_seconds = 5
Expand Down

0 comments on commit c373cc1

Please sign in to comment.