fix: 市场改为勾选列表,楼宇结果输出改为 GBK
This commit is contained in:
@@ -24,7 +24,7 @@ REFERER = "https://nqi.gmcc.net:20443/pro-problem-warehouse-web/"
|
||||
INPUT_CSV = Path(__file__).resolve().parent / "source" / "NRBuildingsPoint.csv"
|
||||
OUTPUT_CSV = Path(__file__).resolve().parent / "output" / "NRBuildingsData.csv"
|
||||
INPUT_ENCODING = "gb18030" # 当前源文件为 GBK;UTF-8 文件可改为 utf-8-sig。
|
||||
OUTPUT_ENCODING = "utf-8-sig" # 带 BOM,方便 Excel 识别中文。
|
||||
OUTPUT_ENCODING = "gbk" # 供 Excel/传统工具直接打开;无法编码的字符用 errors=replace。
|
||||
ID_COLUMN = "序号"
|
||||
LONGITUDE_COLUMN = "经度"
|
||||
LATITUDE_COLUMN = "维度" # 源文件实际写的是“维度”。
|
||||
@@ -122,7 +122,7 @@ class StreamingCsvWriter:
|
||||
def __init__(self, output_path):
|
||||
self.path = output_path
|
||||
self.fields = list(QUERY_COLUMNS)
|
||||
self.file = self.path.open("w", encoding=OUTPUT_ENCODING, newline="")
|
||||
self.file = self.path.open("w", encoding=OUTPUT_ENCODING, newline="", errors="replace")
|
||||
try:
|
||||
self.writer = csv.DictWriter(self.file, fieldnames=self.fields)
|
||||
self.writer.writeheader()
|
||||
@@ -137,16 +137,17 @@ class StreamingCsvWriter:
|
||||
try:
|
||||
# 后出现的字段需补到旧行;独占写线程执行原子替换,其他协程只入队。
|
||||
with tempfile.NamedTemporaryFile("w", encoding=OUTPUT_ENCODING, newline="", delete=False,
|
||||
dir=self.path.parent, prefix=f".{self.path.name}.", suffix=".tmp") as target:
|
||||
dir=self.path.parent, prefix=f".{self.path.name}.", suffix=".tmp",
|
||||
errors="replace") as target:
|
||||
temporary = Path(target.name)
|
||||
writer = csv.DictWriter(target, fieldnames=fields)
|
||||
writer.writeheader()
|
||||
with self.path.open("r", encoding=OUTPUT_ENCODING, newline="") as source:
|
||||
with self.path.open("r", encoding=OUTPUT_ENCODING, newline="", errors="replace") as source:
|
||||
writer.writerows(csv.DictReader(source))
|
||||
self.file.close()
|
||||
temporary.replace(self.path)
|
||||
self.fields = fields
|
||||
self.file = self.path.open("a", encoding=OUTPUT_ENCODING, newline="")
|
||||
self.file = self.path.open("a", encoding=OUTPUT_ENCODING, newline="", errors="replace")
|
||||
self.writer = csv.DictWriter(self.file, fieldnames=self.fields)
|
||||
finally:
|
||||
if temporary is not None:
|
||||
|
||||
Reference in New Issue
Block a user