수정완료

This commit is contained in:
kjy
2025-12-28 22:35:32 +09:00
parent dd854cac08
commit 151d3a0908
11 changed files with 101 additions and 157 deletions

View File

@@ -43,6 +43,7 @@ async function main() {
})
);
}
console.log("매물 정보 업데이트 완료");
} catch (error) {
console.error("오류 발생:", error);
}

View File

@@ -12,6 +12,7 @@ import {
} from "./services/telegram.service";
import type { RealEstateArticle } from "./generated/prisma";
import * as XLSX from "xlsx";
import { unlink } from "node:fs/promises";
const isTestMode = process.argv.includes("--test");
@@ -59,6 +60,8 @@ async function sendTelegram() {
"YYYY-MM-DD"
)})`
);
await unlink(excelFilePath);
console.log("excel file deleted");
}
}

View File

@@ -1,6 +1,8 @@
import TelegramBot from "node-telegram-bot-api";
import fs from "fs";
process.env.NTBA_FIX_350 = "1";
export interface TelegramUser {
site: string;
chatId: number;
@@ -108,7 +110,10 @@ export class TelegramService {
constructor(token: string, enablePolling: boolean = false) {
this.token = token;
this.bot = new TelegramBot(token, { polling: enablePolling });
this.bot = new TelegramBot(token, {
polling: enablePolling,
filepath: false,
});
if (enablePolling) {
this.setupListeners();
@@ -149,16 +154,15 @@ export class TelegramService {
caption?: string
): Promise<void> {
try {
const buffer = Buffer.from(await Bun.file(fileName).arrayBuffer());
await this.bot.sendDocument(
chatId,
fs.createReadStream(fileName),
{
caption: caption || "",
},
buffer,
{ caption: caption || "" },
{
filename: fileName.split("/").pop(),
contentType:
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
contentType: "application/octet-stream",
}
);
console.log(`✅ 문서 전송 성공 - chatId: ${chatId}, file: ${fileName}`);

View File

@@ -1,62 +0,0 @@
import schedule from "node-schedule";
import { exec } from "node:child_process";
console.log("start ...");
function runTsFile(filePath: string): Promise<void> {
return new Promise((resolve, reject) => {
console.log(`Starting: ${filePath}`);
exec(`bun run ${filePath}`, (error, stdout, stderr) => {
if (error) {
console.error(`Execution error: ${error.message}`);
reject(error);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
}
console.log(`Output: ${stdout}`);
console.log(`Completed: ${filePath}`);
resolve();
});
});
}
// 11시에 실행 - fetch-articles -> fetch-detailAddress -> updateRanging -> sendTelegram
schedule.scheduleJob("0 11 * * *", async () => {
console.log("Running scheduled jobs at 11 AM");
try {
await runTsFile("./fetch-articles.ts");
await runTsFile("./fetch-detailAddress.ts");
await runTsFile("./updateRanging.ts");
await runTsFile("./sendTelegram.ts");
} catch (error) {
console.error("Error in 11 AM scheduled job:", error);
}
});
// 16시에 실행 - fetch-articles -> fetch-detailAddress -> updateRanging -> sendTelegram
schedule.scheduleJob("0 16 * * *", async () => {
console.log("Running scheduled jobs at 4 PM");
try {
await runTsFile("./fetch-articles.ts");
await runTsFile("./fetch-detailAddress.ts");
await runTsFile("./updateRanging.ts");
await runTsFile("./sendTelegram.ts");
} catch (error) {
console.error("Error in 4 PM scheduled job:", error);
}
});
// 16시에 실행 - fetch-articles -> fetch-detailAddress -> updateRanging -> sendTelegram
schedule.scheduleJob("05 21 * * *", async () => {
console.log("Running scheduled jobs at 4 PM");
try {
await runTsFile("./fetch-articles.ts");
await runTsFile("./fetch-detailAddress.ts");
// await runTsFile("./updateRanging.ts");
// await runTsFile("./sendTelegram.ts");
} catch (error) {
console.error("Error in 4 PM scheduled job:", error);
}
});