更新导出为csv的方式,字段中有因为,自动转义
This commit is contained in:
parent
2366baaa52
commit
c3cbcc1b2c
@ -12,6 +12,7 @@
|
||||
# Author: xaoyaoo
|
||||
# Date: 2023/11/10
|
||||
# -------------------------------------------------------------------------------
|
||||
import csv
|
||||
import re
|
||||
import sqlite3
|
||||
import os
|
||||
@ -233,7 +234,9 @@ def export_csv(username, outpath, MSG_ALL_db_path, page_size=5000):
|
||||
break
|
||||
save_path = os.path.join(outpath, f"{username}_{i}_{i + page_size}.csv")
|
||||
with open(save_path, "w", encoding="utf-8") as f:
|
||||
f.write("id,MsgSvrID,type_name,is_sender,talker,room_name,content,CreateTime\n")
|
||||
csv_writer = csv.writer(f, quoting=csv.QUOTE_MINIMAL)
|
||||
csv_writer.writerow(["id", "MsgSvrID", "type_name", "is_sender", "talker", "room_name", "content",
|
||||
"CreateTime"])
|
||||
for row in data:
|
||||
id = row.get("id", "")
|
||||
MsgSvrID = row.get("MsgSvrID", "")
|
||||
@ -245,8 +248,8 @@ def export_csv(username, outpath, MSG_ALL_db_path, page_size=5000):
|
||||
CreateTime = row.get("CreateTime", "")
|
||||
|
||||
content = json.dumps(content, ensure_ascii=False)
|
||||
csv_writer.writerow([id, MsgSvrID, type_name, is_sender, talker, room_name, content, CreateTime])
|
||||
|
||||
f.write(f"{id},{MsgSvrID},{type_name},{is_sender},{talker},{room_name},{content},{CreateTime}\n")
|
||||
return True, f"导出成功: {outpath}"
|
||||
|
||||
|
||||
|
@ -295,9 +295,7 @@ class MainExportChatRecords():
|
||||
def run(self, args):
|
||||
# 从命令行参数获取值
|
||||
t = args.type
|
||||
if t not in ["html", "csv"]:
|
||||
print("[-] 未知的导出类型")
|
||||
return
|
||||
|
||||
if t == "txt":
|
||||
try:
|
||||
code, ret = export_csv(args.username, args.outpath, args.msg_path, page_size=10000000)
|
||||
@ -310,28 +308,31 @@ class MainExportChatRecords():
|
||||
print(e)
|
||||
print("[-] 导出失败")
|
||||
return
|
||||
elif t == "html":
|
||||
try:
|
||||
from flask import Flask, request, jsonify, render_template, g
|
||||
import logging
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("[-] 请安装flask( pip install flask)")
|
||||
return
|
||||
|
||||
try:
|
||||
from flask import Flask, request, jsonify, render_template, g
|
||||
import logging
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("[-] 请安装flask( pip install flask)")
|
||||
if not os.path.exists(args.msg_path) or not os.path.exists(args.micro_path) or not os.path.exists(
|
||||
args.media_path):
|
||||
print(os.path.exists(args.msg_path), os.path.exists(args.micro_path), os.path.exists(args.media_path))
|
||||
print("[-] 输入数据库路径不存在")
|
||||
return
|
||||
|
||||
if not os.path.exists(args.outpath):
|
||||
os.makedirs(args.outpath)
|
||||
print(f"[+] 创建输出文件夹:{args.outpath}")
|
||||
|
||||
export(args.username, args.outpath, args.msg_path, args.micro_path, args.media_path, args.filestorage_path)
|
||||
print(f"[+] 导出成功{args.outpath}")
|
||||
else:
|
||||
print("[-] 未知的导出类型")
|
||||
return
|
||||
|
||||
if not os.path.exists(args.msg_path) or not os.path.exists(args.micro_path) or not os.path.exists(
|
||||
args.media_path):
|
||||
print(os.path.exists(args.msg_path), os.path.exists(args.micro_path), os.path.exists(args.media_path))
|
||||
print("[-] 输入数据库路径不存在")
|
||||
return
|
||||
|
||||
if not os.path.exists(args.outpath):
|
||||
os.makedirs(args.outpath)
|
||||
print(f"[+] 创建输出文件夹:{args.outpath}")
|
||||
|
||||
export(args.username, args.outpath, args.msg_path, args.micro_path, args.media_path, args.filestorage_path)
|
||||
print(f"[+] 导出成功{args.outpath}")
|
||||
|
||||
|
||||
class MainAll():
|
||||
def init_parses(self, parser):
|
||||
|
Loading…
Reference in New Issue
Block a user