添加 刷新通讯录功能,用于解决冗余数据问题。
This commit is contained in:
@@ -117,7 +117,7 @@ class ContactsDBOperator(BaseDBOperator):
|
|||||||
Args:
|
Args:
|
||||||
contacts_data: 联系人数据列表
|
contacts_data: 联系人数据列表
|
||||||
contact_type: 联系人类型,可选值:'friends', 'chatrooms', 'ghs'
|
contact_type: 联系人类型,可选值:'friends', 'chatrooms', 'ghs'
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: 是否成功保存
|
bool: 是否成功保存
|
||||||
"""
|
"""
|
||||||
@@ -127,29 +127,34 @@ class ContactsDBOperator(BaseDBOperator):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
for contact in contacts_data:
|
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 = {
|
data = {
|
||||||
'user_name': contact.get('userName', ''),
|
'user_name': get_str('UserName'),
|
||||||
'nick_name': contact.get('nickName', ''),
|
'nick_name': get_str('NickName'),
|
||||||
'py_initial': contact.get('pyInitial', ''),
|
'py_initial': get_str('Pyinitial'),
|
||||||
'quan_pin': contact.get('quanPin', ''),
|
'quan_pin': get_str('QuanPin'),
|
||||||
'sex': contact.get('sex', 0),
|
'sex': contact.get('Sex', 0),
|
||||||
'remark': contact.get('remark', ''),
|
'remark': get_str('Remark'),
|
||||||
'remark_py_initial': contact.get('remarkPyInitial', ''),
|
'remark_py_initial': get_str('RemarkPyinitial'),
|
||||||
'remark_quan_pin': contact.get('remarkQuanPin', ''),
|
'remark_quan_pin': get_str('RemarkQuanPin'),
|
||||||
'signature': contact.get('signature', ''),
|
'signature': contact.get('Signature', ''),
|
||||||
'alias': contact.get('alias', ''),
|
'alias': contact.get('Alias', ''),
|
||||||
'sns_bg_img': contact.get('snsBgImg', ''),
|
'sns_bg_img': contact.get('SnsUserInfo', {}).get('SnsBgimgId', ''),
|
||||||
'country': contact.get('country', ''),
|
'country': contact.get('Country', ''),
|
||||||
'province': contact.get('province', ''),
|
'province': contact.get('Province', ''),
|
||||||
'city': contact.get('city', ''),
|
'city': contact.get('City', ''),
|
||||||
'big_head_img_url': contact.get('bigHeadImgUrl', ''),
|
'big_head_img_url': contact.get('BigHeadImgUrl', ''),
|
||||||
'small_head_img_url': contact.get('smallHeadImgUrl', ''),
|
'small_head_img_url': contact.get('SmallHeadImgUrl', ''),
|
||||||
'description': contact.get('description', ''),
|
'description': '', # 可根据需要补充
|
||||||
'card_img_url': contact.get('cardImgUrl', ''),
|
'card_img_url': '', # 可根据需要补充
|
||||||
'label_list': contact.get('labelList', ''),
|
'label_list': '', # 可根据需要补充
|
||||||
'phone_num_list': json.dumps(contact.get('phoneNumList', [])) if contact.get(
|
'phone_num_list': '',# 可根据需要补充
|
||||||
'phoneNumList') else '',
|
|
||||||
'type': contact_type
|
'type': contact_type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user