From 225e27bf88dff22d54c50fac492e1c50c35c60b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA=E6=80=BB=E5=8A=A8=E5=91=98?= <73592731+devourbots@users.noreply.github.com> Date: Sun, 9 May 2021 12:44:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=98=9F=E5=88=97=E5=8F=91?= =?UTF-8?q?=E9=80=81Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entrypoint.sh | 1 - restart.sh | 2 +- task.py | 27 +++++++++++---------------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 2841ae4..567f66b 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,3 @@ #! /bin/sh \ cd /root/word_cloud_bot && python3 main.py >> output 2>&1 & -cd /root/word_cloud_bot && bash restart.sh 2>&1 & tail -f /dev/null \ No newline at end of file diff --git a/restart.sh b/restart.sh index b4ae7cc..7ccc707 100644 --- a/restart.sh +++ b/restart.sh @@ -9,7 +9,7 @@ do us=`free | awk 'NR==2{print $3}'` to=`free | awk 'NR==2{print $2}'` mem=`expr "scale=2;($us-$bu-$ca)/$to" |bc -l | cut -d. -f2` - if(($mem >= 75)) + if(($mem >= 90)) then echo "restart" killall -9 python3 diff --git a/task.py b/task.py index 0454a67..2410fa0 100644 --- a/task.py +++ b/task.py @@ -52,12 +52,8 @@ def do_task(): print("当前群组处理耗时:" + str(stop_time - start_time)) print("---------------------------") except Exception as e: - print("群组: {} | 处理失败,请检查报错!".format(group)) + print("群组: {} | 处理失败,可能是机器人已经被移出群组,请检查报错!".format(group)) print(e) - bot.send_message( - chat_id=group, - text="当前聊天数据量过小,嗨起来吧~" - ) time.sleep(1) @@ -167,12 +163,6 @@ def generate(group): top_5_user += "\t\t\t\t\t\t\t\t" + "🎖`" + str(user_message_amount[i][0]) + "`" + " 贡献: " + str( user_message_amount[i][1]) + "\n" # print(top_5_user) - string = " ".join(word_list) - # 将string变量传入w的generate()方法,给词云输入文字 - w.generate(string) - # 将词云图片导出到当前文件夹 - w.to_file('{}_chat_word_cloud.png'.format(group)) - bot.send_message( chat_id=group, text="🏵 今日活跃用户排行榜 🏵\n" @@ -193,6 +183,11 @@ def generate(group): ) try: + string = " ".join(word_list) + # 将string变量传入w的generate()方法,给词云输入文字 + w.generate(string) + # 将词云图片导出到当前文件夹 + w.to_file('{}_chat_word_cloud.png'.format(group)) bot.send_photo( chat_id=group, photo=open("{}_chat_word_cloud.png".format(group), "rb") @@ -200,11 +195,11 @@ def generate(group): os.remove("{}_chat_word_cloud.png".format(group)) except Exception as e: print(e) - bot.send_message( - chat_id=group, - text="当前聊天数据量过小,嗨起来吧~" - ) - return + print("词云图片生成失败") + # bot.send_message( + # chat_id=group, + # text="当前聊天数据量过小,嗨起来吧~" + # ) def flush_redis():