상세주소 번지 일반주소로 옮김
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
testUsers,
|
||||
type TelegramUser,
|
||||
} from "./services/telegram.service";
|
||||
|
||||
import type { RealEstateArticle } from "./generated/prisma";
|
||||
import * as XLSX from "xlsx";
|
||||
import { unlink } from "node:fs/promises";
|
||||
@@ -21,6 +22,41 @@ const telegramService = new TelegramService(
|
||||
false
|
||||
);
|
||||
|
||||
function splitAddress(
|
||||
detailAddress: string | null | undefined,
|
||||
baseAddress: string
|
||||
) {
|
||||
const safeDetail = detailAddress?.trim() || "";
|
||||
const base = baseAddress.trim();
|
||||
|
||||
if (!safeDetail) {
|
||||
return { address: base, detailAddress: "" };
|
||||
}
|
||||
|
||||
const match = safeDetail.match(
|
||||
/(^|[\s,])([\d]{1,6}(?:-[\d]{1,6})?)(?:\s*번지)?(?=[\s,]|$)/
|
||||
);
|
||||
if (!match) {
|
||||
return { address: base, detailAddress: safeDetail };
|
||||
}
|
||||
|
||||
const rawToken = match[2];
|
||||
if (!rawToken) {
|
||||
return { address: base, detailAddress: safeDetail };
|
||||
}
|
||||
|
||||
const lot = rawToken.replace(/\s+/g, "");
|
||||
const removed = safeDetail
|
||||
.replace(new RegExp(`(^|[\\s,])${rawToken}(?:\\s*번지)?(?=[\\s,]|$)`), "")
|
||||
.replace(/\s{2,}/g, " ")
|
||||
.trim();
|
||||
|
||||
return {
|
||||
address: [base, lot].filter(Boolean).join(" ").trim(),
|
||||
detailAddress: removed,
|
||||
};
|
||||
}
|
||||
|
||||
function logWithTime(...args: unknown[]) {
|
||||
console.log(`[${dayjs().format("YYYY-MM-DD HH:mm:ss")}]`, ...args);
|
||||
}
|
||||
@@ -106,6 +142,10 @@ async function createExcelFile(
|
||||
const getPrice = () => {
|
||||
return item.prcInfo;
|
||||
};
|
||||
const normalizedAddress = splitAddress(
|
||||
item.detailAddress || "",
|
||||
`${item.city || ""} ${item.division || ""} ${item.sector || ""}`
|
||||
);
|
||||
|
||||
return {
|
||||
매물번호: item.articleNumber,
|
||||
@@ -113,8 +153,8 @@ async function createExcelFile(
|
||||
소유자구분: getOwnerType(),
|
||||
매물형태: item.articleName || "",
|
||||
매매구분: item.tradTpNm || "",
|
||||
주소: `${item.city || ""} ${item.division || ""} ${item.sector || ""}`,
|
||||
상세주소: item.detailAddress || "",
|
||||
주소: normalizedAddress.address,
|
||||
상세주소: normalizedAddress.detailAddress,
|
||||
층수: item.floorInfo || "",
|
||||
가격: getPrice(),
|
||||
매물특징: item.articleDescription || "",
|
||||
|
||||
Reference in New Issue
Block a user