diff --git a/pywxdump/api/remote_server.py b/pywxdump/api/remote_server.py index 0a8eb5e..a1acef7 100644 --- a/pywxdump/api/remote_server.py +++ b/pywxdump/api/remote_server.py @@ -12,6 +12,8 @@ import os import re import time import shutil +from collections import Counter + import pythoncom import pywxdump @@ -495,7 +497,51 @@ def get_top_talker_count(): @rs_api.route('/api/rs/wordcloud', methods=["GET", 'POST']) @error9999 def wordcloud(): - pass + if request.method not in ["GET", "POST"]: + return ReJson(1003, msg="Unsupported method") + rq_data = request.json if request.method == "POST" else request.args + + try: + import jieba + except ImportError: + return ReJson(9999, body="jieba is required") + + target = rq_data.get("target", "") + print(target) + if not target: + return ReJson(1002, body="target is required") + my_wxid = get_conf(g.caf, g.at, "last") + if not my_wxid: return ReJson(1001, body="my_wxid is required") + db_config = get_conf(g.caf, my_wxid, "db_config") + db = DBHandler(db_config) + + if target == "signature": + users = db.get_user() + signature_list = [] + for wxid, user in users.items(): + ExtraBuf = user.get("ExtraBuf", {}) + signature = ExtraBuf.get("个性签名", "") if ExtraBuf else "" + if signature: + signature_list.append(signature) + signature_str = " ".join(signature_list) + words = jieba.lcut(signature_str) + words = [word for word in words if len(word) > 1] + count_dict = dict(Counter(words)) + return ReJson(0, count_dict) + elif target == "nickname": + users = db.get_user() + nickname_list = [] + for wxid, user in users.items(): + nickname = user.get("nickname", "") + if nickname: + nickname_list.append(nickname) + nickname_str = " ".join(nickname_list) + words = jieba.lcut(nickname_str) + words = [word for word in words if len(word) > 1] + count_dict = dict(Counter(words)) + return ReJson(0, count_dict) + + return ReJson(1002, body="target is required") # end 聊天记录分析api **************************************************************************************************** diff --git a/pywxdump/db/__init__.py b/pywxdump/db/__init__.py index a5e6f30..c067b91 100644 --- a/pywxdump/db/__init__.py +++ b/pywxdump/db/__init__.py @@ -46,7 +46,6 @@ class DBHandler(MicroHandler, MediaHandler, OpenIMContactHandler, PublicMsgHandl """ 获取联系人列表 """ - users = self.get_user_list(word=word, wxids=wxids, label_ids=labels) - if self.OpenIMContact_exist: - users.update(self.get_im_user_list(word=word, wxids=wxids)) + users = self.get_user_list(word=word, wxids=wxids, label_ids=labels) if self.Micro_exist else {} + if self.OpenIMContact_exist: users.update(self.get_im_user_list(word=word, wxids=wxids)) return users