先初始化数据库
This commit is contained in:
@@ -87,9 +87,9 @@ class ContactsDBOperator(BaseDBOperator):
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='微信群成员信息表';
|
||||
""")
|
||||
|
||||
self.logger.info("成功创建或确认微信联系人表和群成员表存在")
|
||||
logger.info("成功创建或确认微信联系人表和群成员表存在")
|
||||
except Exception as e:
|
||||
self.logger.error(f"创建微信联系人表或群成员表失败: {e}")
|
||||
logger.error(f"创建微信联系人表或群成员表失败: {e}")
|
||||
raise
|
||||
|
||||
def save_contacts(self, contacts_data: List[Dict], contact_type: str) -> bool:
|
||||
@@ -103,7 +103,7 @@ class ContactsDBOperator(BaseDBOperator):
|
||||
bool: 是否成功保存
|
||||
"""
|
||||
if not contacts_data:
|
||||
self.logger.warning(f"没有{contact_type}类型的联系人数据需要保存")
|
||||
logger.warning(f"没有{contact_type}类型的联系人数据需要保存")
|
||||
return True
|
||||
|
||||
try:
|
||||
@@ -150,11 +150,11 @@ class ContactsDBOperator(BaseDBOperator):
|
||||
|
||||
self.execute_update(sql, values)
|
||||
|
||||
self.logger.info(f"成功保存{len(contacts_data)}个{contact_type}类型的联系人")
|
||||
logger.info(f"成功保存{len(contacts_data)}个{contact_type}类型的联系人")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"保存{contact_type}类型的联系人失败: {e}")
|
||||
logger.error(f"保存{contact_type}类型的联系人失败: {e}")
|
||||
return False
|
||||
|
||||
def save_simple_contacts(self, contact_list: List[str], contact_type: str) -> bool:
|
||||
@@ -168,7 +168,7 @@ class ContactsDBOperator(BaseDBOperator):
|
||||
bool: 是否成功保存
|
||||
"""
|
||||
if not contact_list:
|
||||
self.logger.warning(f"没有{contact_type}类型的联系人数据需要保存")
|
||||
logger.warning(f"没有{contact_type}类型的联系人数据需要保存")
|
||||
return True
|
||||
|
||||
try:
|
||||
@@ -182,11 +182,11 @@ class ContactsDBOperator(BaseDBOperator):
|
||||
|
||||
self.execute_update(sql, (user_name, contact_type))
|
||||
|
||||
self.logger.info(f"成功保存{len(contact_list)}个{contact_type}类型的简单联系人")
|
||||
logger.info(f"成功保存{len(contact_list)}个{contact_type}类型的简单联系人")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"保存{contact_type}类型的简单联系人失败: {e}")
|
||||
logger.error(f"保存{contact_type}类型的简单联系人失败: {e}")
|
||||
return False
|
||||
|
||||
def get_contacts_by_type(self, contact_type: str) -> List[Dict]:
|
||||
@@ -208,7 +208,7 @@ class ContactsDBOperator(BaseDBOperator):
|
||||
results = self.execute_query(sql, (contact_type,))
|
||||
return results
|
||||
except Exception as e:
|
||||
self.logger.error(f"获取{contact_type}类型的联系人失败: {e}")
|
||||
logger.error(f"获取{contact_type}类型的联系人失败: {e}")
|
||||
return []
|
||||
|
||||
def get_contact_by_user_name(self, user_name: str) -> Optional[Dict]:
|
||||
@@ -230,7 +230,7 @@ class ContactsDBOperator(BaseDBOperator):
|
||||
result = self.execute_query(sql, (user_name,), fetch_one=True)
|
||||
return result
|
||||
except Exception as e:
|
||||
self.logger.error(f"获取联系人{user_name}失败: {e}")
|
||||
logger.error(f"获取联系人{user_name}失败: {e}")
|
||||
return None
|
||||
|
||||
def get_display_name(self, user_name: str) -> str:
|
||||
@@ -271,7 +271,7 @@ class ContactsDBOperator(BaseDBOperator):
|
||||
|
||||
return name_map
|
||||
except Exception as e:
|
||||
self.logger.error(f"获取所有联系人名称映射失败: {e}")
|
||||
logger.error(f"获取所有联系人名称映射失败: {e}")
|
||||
return {}
|
||||
|
||||
def save_chatroom_member_detail(self, chatroom_id: str, member_details: List[Dict]) -> bool:
|
||||
@@ -285,7 +285,7 @@ class ContactsDBOperator(BaseDBOperator):
|
||||
bool: 是否成功保存
|
||||
"""
|
||||
if not member_details or not chatroom_id:
|
||||
self.logger.warning(f"没有群聊{chatroom_id}的成员详细信息需要保存")
|
||||
logger.warning(f"没有群聊{chatroom_id}的成员详细信息需要保存")
|
||||
return False
|
||||
|
||||
try:
|
||||
@@ -354,11 +354,11 @@ class ContactsDBOperator(BaseDBOperator):
|
||||
|
||||
self.execute_update(sql, values)
|
||||
|
||||
self.logger.info(f"成功保存群聊{chatroom_id}的{len(member_details)}个成员详细信息")
|
||||
logger.info(f"成功保存群聊{chatroom_id}的{len(member_details)}个成员详细信息")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"保存群聊{chatroom_id}的成员详细信息失败: {e}")
|
||||
logger.error(f"保存群聊{chatroom_id}的成员详细信息失败: {e}")
|
||||
return False
|
||||
|
||||
def process_chatroom_member_detail_response(self, chatroom_id: str, response: Dict) -> bool:
|
||||
@@ -373,16 +373,16 @@ class ContactsDBOperator(BaseDBOperator):
|
||||
"""
|
||||
try:
|
||||
if response.get('ret') != 200:
|
||||
self.logger.error(f"获取群聊{chatroom_id}成员详情失败: {response.get('msg')}")
|
||||
logger.error(f"获取群聊{chatroom_id}成员详情失败: {response.get('msg')}")
|
||||
return False
|
||||
|
||||
data = response.get('data', [])
|
||||
if not data:
|
||||
self.logger.warning(f"群聊{chatroom_id}成员详情数据为空")
|
||||
logger.warning(f"群聊{chatroom_id}成员详情数据为空")
|
||||
return False
|
||||
|
||||
return self.save_chatroom_member_detail(chatroom_id, data)
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"处理群聊{chatroom_id}成员详情数据失败: {e}")
|
||||
logger.error(f"处理群聊{chatroom_id}成员详情数据失败: {e}")
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user