diff --git a/index.js b/index.js index cf63ee1..7c03c10 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ import fetch from 'node-fetch'; import postgres from 'postgres'; -import { drizzle } from 'drizzle-orm/postgres-js'; -import { pgTable, text } from 'drizzle-orm/pg-core'; +import {drizzle} from 'drizzle-orm/postgres-js'; +import {pgTable, text} from 'drizzle-orm/pg-core'; // PostgreSQL 데이터베이스 연결 설정 const sql = postgres({ @@ -155,45 +155,42 @@ const niceTable = pgTable('nice', { async function main() { const baseUrl = 'https://nice.kegorii.workers.dev/get?t='; - const firstArray = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'H', 'I', 'J', 'L', 'M', 'N', 'O', 'P', 'Q']; + const firstArray = ['S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; for (let i = 0; i < firstArray.length; i++) { let secondArray = []; if (i >= 0 && i <= 9) { secondArray = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; - } else { - secondArray = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; - } - for (let x = 0; x < secondArray.length; x++) { - for (let y = 0; y < 1000; y++) { - const rtnval = y.toString().padStart(3, '0'); - const kiscode = firstArray[i] + secondArray[x] + rtnval; - const url = `${baseUrl}${kiscode}`; - try { - const startTime = Date.now(); // 시작 시간 저장 + for (let x = 0; x < secondArray.length; x++) { + for (let y = 0; y < 1000; y++) { + const rtnval = y.toString().padStart(3, '0'); + const kiscode = firstArray[i] + secondArray[x] + rtnval; + const url = `${baseUrl}${kiscode}`; + try { + const startTime = Date.now(); // 시작 시간 저장 - const response = await fetch(url); + const response = await fetch(url); - if (!response.ok) { - throw new Error(`Request failed: ${response.statusText}`); + if (!response.ok) { + throw new Error(`Request failed: ${response.statusText}`); + } + + const jsonData = await response.json(); + const insertValues = jsonData.map(item => ({ + ...item // 모든 데이터를 그대로 삽입 (데이터 정제 필요) + })); + + if (insertValues.length > 0) { + await orm.insert(niceTable).values(insertValues); + } + + const endTime = Date.now(); // 종료 시간 저장 + console.log(`Execution time for kiscode:${kiscode}: ${endTime - startTime} ms`); // 콘솔에 시간 출력 + } catch (error) { + console.error(`Error at kiscode:${kiscode}`, error); } - - const jsonData = await response.json(); - const insertValues = jsonData.map(item => ({ - ...item // 모든 데이터를 그대로 삽입 (데이터 정제 필요) - })); - - if (insertValues.length > 0) { - await orm.insert(niceTable).values(insertValues); - } - - const endTime = Date.now(); // 종료 시간 저장 - console.log(`Execution time for kiscode:${kiscode}: ${endTime - startTime} ms`); // 콘솔에 시간 출력 - } catch (error) { - console.error(`Error at kiscode:${kiscode}`, error); } } } } -} -main(); \ No newline at end of file + main(); \ No newline at end of file