def data_ctrl(self, msg): """ 打印基础消息并整理 """ msg_type = msg["MsgType"] sub_type = msg["SubMsgType"] is_me = self.msg_is_self(msg) is_group = "@@" in msg["FromUserName"] content_header = "👥" if is_group else "💬" to_user_name = "" if is_group else f'-> 【{msg["ToUserName"]}】' func = info if is_me else success content = f'{content_header}【{msg["FromUserName"]}】{to_user_name}:' result = { "time": msg["CreateTime"], "from": msg["FromUserName"], "from_nick": self.translate_text(msg["FromUserName"]), "to": msg["ToUserName"], "to_nick": self.translate_text(msg["ToUserName"]), "type": MSG_TYPES[msg_type].lower(), "content": "", "raw_content": msg["Content"], "is_me": is_me, "is_group": is_group, } if msg_type == MSGTYPE_TEXT: if sub_type == 0: result["content"] = msg["Content"] elif sub_type == 48: result["content"] = msg["Content"].split(":")[0] elif msg_type == MSGTYPE_VOICE: voice = self.get_voice(msg["MsgId"], conf.play_voice) filename = f"datas/{msg['MsgId']}.mp3" save_file(voice, filename) result["content"] = filename elif msg_type == MSGTYPE_EMOTICON: urls = URLExtract().find_urls(msg["Content"]) if not urls: return imgcat(Image.open(BytesIO(get_pic(self.__session, urls[0], True)))) result["content"] = urls[0] elif msg_type == MSGTYPE_APP: pass # content += "公众号推送" elif msg_type == MSGTYPE_STATUSNOTIFY: # content += "进入/退出" pass if msg_type not in [] and result["content"]: func(self.translate_text(content + result["content"])) return msg, result
def export_all_contact(contacts: dict, session: requests.Session, person_data: dict) -> pathlib.Path: """ 导出通讯录 """ warning("Contact exporting...") wb = Workbook() sheet = wb.active keys = contacts["MemberList"][0].keys() for x, key in enumerate(keys): sheet.cell(row=1, column=x + 1, value=key) for y, item in progressbar.progressbar( enumerate(contacts["MemberList"])): y = y + 2 for x, key in enumerate(keys): x = x + 1 data = item[key] if key != "HeadImgUrl": if key == "MemberList": data = "".join(data) sheet.cell(row=y, column=x, value=data) else: pic = get_pic( session, urljoin(API_target, data), API_media_icon_path / f"{item['PYInitial']}_{item['VerifyFlag']}.png", ) if pic: x = x - 1 index_code = string.ascii_uppercase[x] size = (50, 50) ( sheet.column_dimensions[index_code].width, sheet.row_dimensions[y].height, ) = size img = openpyxlImage(BytesIO(pic)) img.width, img.height = size sheet.add_image(img, f"{index_code}{y}") else: sheet.cell(row=y, column=x, value="") path = API_analysis_path / f'{person_data["User"]["NickName"]}_contacts.xlsx' wb.save(path) success(f"export contacts: {path}") return path
def export_all_contact(contacts, session, person_data): """ 导出通讯录 """ warning("Contact exporting...") wb = Workbook() sheet = wb.active keys = contacts["MemberList"][0].keys() for x, key in enumerate(keys): sheet.cell(row=1, column=x + 1, value=key) for y, item in progressbar.progressbar( enumerate(contacts["MemberList"])): y = y + 2 for x, key in enumerate(keys): x = x + 1 data = item[key] if key != "HeadImgUrl": if key == "MemberList": data = "".join(data) sheet.cell(row=y, column=x, value=data) else: picData = get_pic(session, data) if picData: x = x - 1 indexCode = string.ascii_uppercase[x] size = (50, 50) sheet.column_dimensions[ indexCode].width, sheet.row_dimensions[ y].height = size img = openpyxlImage(BytesIO(picData)) img.width, img.height = size sheet.add_image(img, f"{indexCode}{y}") else: sheet.cell(row=y, column=x, value="") wb.save( f'{API_conf_path}/{person_data["User"]["NickName"]}_contacts.xlsx') success("Complete!")
def data_ctrl(self, msg): """ 打印基础消息并整理 """ msg_type = msg["MsgType"] sub_type = msg["SubMsgType"] is_me = self.msg_is_self(msg) is_group = "@@" in msg["FromUserName"] content_header = "👥" if is_group else "💬" to_user_name = "" if is_group else f'-> 【{msg["ToUserName"]}】' func = info if is_me else success content = f'{content_header}【{msg["FromUserName"]}】{to_user_name}:' create_json(msg, str(API_static_path / "⚡️current_msg.json")) # 实时日志分析 result = { "time": msg["CreateTime"], "from": msg["FromUserName"], "from_nick": self.translate_text(msg["FromUserName"]), "to": msg["ToUserName"], "to_nick": self.translate_text(msg["ToUserName"]), "type": MSG_TYPES[msg_type].lower(), "content": "", "raw_content": msg["Content"], "is_me": is_me, "is_group": is_group, } number = f"{result['time']}_{result['from_nick']}_{msg['MsgId']}" # 消息编号 if msg_type == MSGTYPE_TEXT: if sub_type == 0: result["content"] = msg["Content"] elif sub_type == 48: result["content"] = msg["Content"].split(":")[0] self.on_text(result) elif msg_type == MSGTYPE_VOICE: voice = self.get_voice(msg["MsgId"], conf.play_voice) filename = str(API_meida_voice_path / f"{number}.mp3") save_file(voice, filename) result["content"] = filename self.on_voice(result) elif msg_type == MSGTYPE_VIDEO: video = self.get_video(msg["MsgId"], True) filename = str(API_meida_video_path / f"{number}.mp4") save_file(video, filename) result["content"] = filename self.on_video(result) elif msg_type == MSGTYPE_IMAGE: image = self.get_image(msg["MsgId"], True) filename = str(API_meida_image_path / f"{number}.png") save_file(image, filename) result["content"] = filename self.on_image(result) elif msg_type == MSGTYPE_EMOTICON: urls = URLExtract().find_urls(msg["Content"]) if not urls: return filename = str(API_meida_emoji_path / f"{number}.png") imgcat(get_pic(self.__session, urls[0], filename)) result["content"] = urls[0] self.on_emoji(result) elif msg_type == MSGTYPE_APP: pass # content += "公众号推送" elif msg_type == MSGTYPE_STATUSNOTIFY: # content += "进入/退出" pass if msg_type not in [] and result["content"]: func(self.translate_text(content + result["content"])) return msg, result