更新导出为csv的方式,字段中有因为,自动转义
This commit is contained in:
parent
5bb5ea9021
commit
975baf8796
@ -226,6 +226,8 @@ def export_csv(username, outpath, MSG_ALL_db_path, page_size=5000):
|
|||||||
chatCount = count.get(username, 0)
|
chatCount = count.get(username, 0)
|
||||||
if chatCount == 0:
|
if chatCount == 0:
|
||||||
return False, "没有聊天记录"
|
return False, "没有聊天记录"
|
||||||
|
if page_size > chatCount:
|
||||||
|
page_size = chatCount + 1
|
||||||
for i in range(0, chatCount, page_size):
|
for i in range(0, chatCount, page_size):
|
||||||
start_index = i
|
start_index = i
|
||||||
data = get_msg_list(MSG_ALL_db_path, username, start_index, page_size)
|
data = get_msg_list(MSG_ALL_db_path, username, start_index, page_size)
|
||||||
@ -233,7 +235,7 @@ def export_csv(username, outpath, MSG_ALL_db_path, page_size=5000):
|
|||||||
return False, "没有聊天记录"
|
return False, "没有聊天记录"
|
||||||
break
|
break
|
||||||
save_path = os.path.join(outpath, f"{username}_{i}_{i + page_size}.csv")
|
save_path = os.path.join(outpath, f"{username}_{i}_{i + page_size}.csv")
|
||||||
with open(save_path, "w", encoding="utf-8") as f:
|
with open(save_path, "w", encoding="utf-8", newline='') as f:
|
||||||
csv_writer = csv.writer(f, quoting=csv.QUOTE_MINIMAL)
|
csv_writer = csv.writer(f, quoting=csv.QUOTE_MINIMAL)
|
||||||
csv_writer.writerow(["id", "MsgSvrID", "type_name", "is_sender", "talker", "room_name", "content",
|
csv_writer.writerow(["id", "MsgSvrID", "type_name", "is_sender", "talker", "room_name", "content",
|
||||||
"CreateTime"])
|
"CreateTime"])
|
||||||
|
Loading…
Reference in New Issue
Block a user