读取群聊数据,主要为 wxid,以及对应昵称
This commit is contained in:
parent
fba58803b9
commit
d1d92cfa0d
@ -251,6 +251,25 @@ def wordcloud_generator(text, out_path="", is_show=False, img_path="", font="C:\
|
|||||||
wordcloud_img.show()
|
wordcloud_img.show()
|
||||||
|
|
||||||
|
|
||||||
|
def convert_bytes_to_str(d):
|
||||||
|
"""
|
||||||
|
遍历字典并将bytes转换为字符串
|
||||||
|
:param d:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
for k, v in d.items():
|
||||||
|
if isinstance(v, dict):
|
||||||
|
convert_bytes_to_str(v)
|
||||||
|
elif isinstance(v, list):
|
||||||
|
for item in v:
|
||||||
|
if isinstance(item, dict):
|
||||||
|
convert_bytes_to_str(item)
|
||||||
|
elif isinstance(item, bytes):
|
||||||
|
item = item.decode('utf-8') # 将bytes转换为字符串
|
||||||
|
elif isinstance(v, bytes):
|
||||||
|
d[k] = v.decode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
def read_BytesExtra(BytesExtra):
|
def read_BytesExtra(BytesExtra):
|
||||||
if BytesExtra is None or not isinstance(BytesExtra, bytes):
|
if BytesExtra is None or not isinstance(BytesExtra, bytes):
|
||||||
return None
|
return None
|
||||||
@ -258,4 +277,16 @@ def read_BytesExtra(BytesExtra):
|
|||||||
deserialize_data, message_type = blackboxprotobuf.decode_message(BytesExtra)
|
deserialize_data, message_type = blackboxprotobuf.decode_message(BytesExtra)
|
||||||
return deserialize_data
|
return deserialize_data
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def read_ChatRoom_RoomData(RoomData):
|
||||||
|
# 读取群聊数据,主要为 wxid,以及对应昵称
|
||||||
|
if RoomData is None or not isinstance(RoomData, bytes):
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
data = read_BytesExtra(RoomData)
|
||||||
|
convert_bytes_to_str(data)
|
||||||
|
return data
|
||||||
|
except Exception as e:
|
||||||
|
return None
|
||||||
|
@ -20,6 +20,7 @@ def time_int2str(time_int):
|
|||||||
"""
|
"""
|
||||||
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time_int))
|
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time_int))
|
||||||
|
|
||||||
|
|
||||||
def read_dict_all_values(data):
|
def read_dict_all_values(data):
|
||||||
"""
|
"""
|
||||||
读取字典中所有的值(单层)
|
读取字典中所有的值(单层)
|
||||||
@ -199,7 +200,6 @@ class DBPool:
|
|||||||
cls.__db_pool[db_path] = sqlite3.connect(db_path, check_same_thread=False)
|
cls.__db_pool[db_path] = sqlite3.connect(db_path, check_same_thread=False)
|
||||||
cls.connection = cls.__db_pool[db_path]
|
cls.connection = cls.__db_pool[db_path]
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, db_path):
|
def __init__(self, db_path):
|
||||||
if db_path == "DBPOOL_INIT":
|
if db_path == "DBPOOL_INIT":
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user