添加 刷新通讯录功能,用于解决冗余数据问题。

This commit is contained in:
liuwei
2025-05-07 12:19:22 +08:00
parent 77ebca09b6
commit 86c8ad4889

View File

@@ -117,7 +117,7 @@ class ContactsDBOperator(BaseDBOperator):
Args:
contacts_data: 联系人数据列表
contact_type: 联系人类型,可选值:'friends', 'chatrooms', 'ghs'
Returns:
bool: 是否成功保存
"""
@@ -127,29 +127,34 @@ class ContactsDBOperator(BaseDBOperator):
try:
for contact in contacts_data:
# 将驼峰命名转换为下划线命名
# 兼容微信协议风格的数据结构
def get_str(field, default=""):
val = contact.get(field, default)
if isinstance(val, dict):
return val.get("string", default)
return val if val is not None else default
data = {
'user_name': contact.get('userName', ''),
'nick_name': contact.get('nickName', ''),
'py_initial': contact.get('pyInitial', ''),
'quan_pin': contact.get('quanPin', ''),
'sex': contact.get('sex', 0),
'remark': contact.get('remark', ''),
'remark_py_initial': contact.get('remarkPyInitial', ''),
'remark_quan_pin': contact.get('remarkQuanPin', ''),
'signature': contact.get('signature', ''),
'alias': contact.get('alias', ''),
'sns_bg_img': contact.get('snsBgImg', ''),
'country': contact.get('country', ''),
'province': contact.get('province', ''),
'city': contact.get('city', ''),
'big_head_img_url': contact.get('bigHeadImgUrl', ''),
'small_head_img_url': contact.get('smallHeadImgUrl', ''),
'description': contact.get('description', ''),
'card_img_url': contact.get('cardImgUrl', ''),
'label_list': contact.get('labelList', ''),
'phone_num_list': json.dumps(contact.get('phoneNumList', [])) if contact.get(
'phoneNumList') else '',
'user_name': get_str('UserName'),
'nick_name': get_str('NickName'),
'py_initial': get_str('Pyinitial'),
'quan_pin': get_str('QuanPin'),
'sex': contact.get('Sex', 0),
'remark': get_str('Remark'),
'remark_py_initial': get_str('RemarkPyinitial'),
'remark_quan_pin': get_str('RemarkQuanPin'),
'signature': contact.get('Signature', ''),
'alias': contact.get('Alias', ''),
'sns_bg_img': contact.get('SnsUserInfo', {}).get('SnsBgimgId', ''),
'country': contact.get('Country', ''),
'province': contact.get('Province', ''),
'city': contact.get('City', ''),
'big_head_img_url': contact.get('BigHeadImgUrl', ''),
'small_head_img_url': contact.get('SmallHeadImgUrl', ''),
'description': '', # 可根据需要补充
'card_img_url': '', # 可根据需要补充
'label_list': '', # 可根据需要补充
'phone_num_list': '',# 可根据需要补充
'type': contact_type
}