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():