From 7609d39916f759035b83a8e0125b93d8acfa2125 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: Sat, 8 May 2021 11:29:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=BB=E5=8A=A8=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E4=BB=BB=E5=8A=A1=E5=91=BD=E4=BB=A4=20=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=BB=BB=E5=8A=A1=E9=98=9F=E5=88=97=E6=9C=BA=E5=88=B6?= =?UTF-8?q?=20=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE=E6=AF=8F=E4=B8=AA?= =?UTF-8?q?=E7=BE=A4=E7=BB=84=E6=AF=8F=E5=B0=8F=E6=97=B6=E4=B8=BB=E5=8A=A8?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E6=AC=A1=E6=95=B0=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- func.py | 2 +- main.py | 2 +- task.py | 32 ++++++++++++++++---------------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index f0d071e..3dc3a63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ RUN rm -rf /etc/localtime RUN ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime RUN cd /root \ && git clone https://github.com/devourbots/word_cloud_bot.git -RUN echo 'TOKEN = "这里输入机器人token"' > /root/word_cloud_bot/config.py +RUN echo sed '1c TOKEN = "这里输入机器人token"' /root/word_cloud_bot/config.py COPY entrypoint.sh /root/entrypoint.sh RUN chmod +x /root/entrypoint.sh \ && pip3 install -r /root/word_cloud_bot/requirements.txt diff --git a/func.py b/func.py index ba1d378..c81636b 100644 --- a/func.py +++ b/func.py @@ -57,7 +57,7 @@ def rank(update, context): update.message.reply_text("该群组在这个小时内的生成配额已经用完,请稍后再试~") return add_task(chat_id) - print("群组: {},用户: {}|{} 发起了主动触发请求".format(username, user_id, chat_id)) + print("群组: {},用户: {}|{} 发起了主动触发请求".format(chat_id, username, user_id, )) update.message.reply_text("统计数据将在分析完毕后发送到当前群组,请稍等~") except Exception as e: print("主动触发任务失败,请检查") diff --git a/main.py b/main.py index c3f8e9b..9c5381f 100644 --- a/main.py +++ b/main.py @@ -11,7 +11,7 @@ schedule.every().day.at('23:30').do(schedule_task) schedule.every().day.at('23:59').do(flush_redis) # 测试代码,每分钟推送数据,非测试目的不要取消注释下一行 -# schedule.every(1).minutes.do(do_task) +# schedule.every(1).minutes.do(schedule_task) # 开启分析线程,当队列中由任务时,会取出任务分析生成数据 threading.Thread(target=do_task).start() diff --git a/task.py b/task.py index e8d8305..aa84f0e 100644 --- a/task.py +++ b/task.py @@ -24,6 +24,7 @@ def schedule_task(): if "chat_content" in i: group_list.append(i[:i.find("_")]) # print(group_list) + print("运行定时任务,让任务队列中添加任务,任务数量:{}".format(len(group_list))) for group in group_list: try: # 网任务队列中添加任务 @@ -53,6 +54,10 @@ def do_task(): except Exception as e: print("群组: {} | 处理失败,请检查报错!".format(group)) print(e) + bot.send_message( + chat_id=group, + text="当前聊天数据量过小,嗨起来吧~" + ) time.sleep(1) @@ -79,29 +84,23 @@ def generate(group): if chat_content is None: print("数据库中不存在此群组数据") try: + time.sleep(1) bot.send_message( chat_id=group, - text="数据库中不存在群组数据,请检查是否授予机器人管理员权限\n" + text="数据库中不存在群组数据,请检查是否授予机器人管理员权限,并通过聊天添加数据量,嗨起来吧~\n" ) except Exception as e: print("群组: {} | 机器人发送信息失败".format(group)) return word_list = [] - try: - words = pseg.cut(chat_content, use_paddle=True) # paddle模式 - for word, flag in words: - # print(word + "\t" + flag) - if flag in ["n", "nr", "nz", "PER", "f", "ns", "LOC", "s", "nt", "ORG", "nw"]: - # 判断该词是否有效,不为空格 - if re.match(r"^\s+?$", word) is None: - word_list.append(word) - except Exception as e: - print(e) - bot.send_message( - chat_id=group, - text="当前聊天数据量过小,无法生成词云,嗨起来吧~\n" - ) - # print(word_list) + words = pseg.cut(chat_content, use_paddle=True) # paddle模式 + for word, flag in words: + # print(word + "\t" + flag) + if flag in ["n", "nr", "nz", "PER", "f", "ns", "LOC", "s", "nt", "ORG", "nw"]: + # 判断该词是否有效,不为空格 + if re.match(r"^\s+?$", word) is None: + word_list.append(word) + # print(word_list) # 获取消息总数 total_message_amount = r.get("{}_total_message_amount".format(group)) @@ -205,6 +204,7 @@ def generate(group): chat_id=group, text="当前聊天数据量过小,嗨起来吧~" ) + return def flush_redis():