- import 구문 스타일 수정
- 첫 번째 배열 값 변경 - 불필요한 조건 및 중복 코드 제거
This commit is contained in:
parent
9f3cb0be3e
commit
78517042b4
61
index.js
61
index.js
@ -1,7 +1,7 @@
|
|||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import postgres from 'postgres';
|
import postgres from 'postgres';
|
||||||
import { drizzle } from 'drizzle-orm/postgres-js';
|
import {drizzle} from 'drizzle-orm/postgres-js';
|
||||||
import { pgTable, text } from 'drizzle-orm/pg-core';
|
import {pgTable, text} from 'drizzle-orm/pg-core';
|
||||||
|
|
||||||
// PostgreSQL 데이터베이스 연결 설정
|
// PostgreSQL 데이터베이스 연결 설정
|
||||||
const sql = postgres({
|
const sql = postgres({
|
||||||
@ -155,45 +155,42 @@ const niceTable = pgTable('nice', {
|
|||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const baseUrl = 'https://nice.kegorii.workers.dev/get?t=';
|
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++) {
|
for (let i = 0; i < firstArray.length; i++) {
|
||||||
let secondArray = [];
|
let secondArray = [];
|
||||||
if (i >= 0 && i <= 9) {
|
if (i >= 0 && i <= 9) {
|
||||||
secondArray = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
secondArray = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
||||||
} else {
|
for (let x = 0; x < secondArray.length; x++) {
|
||||||
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 y = 0; y < 1000; y++) {
|
||||||
}
|
const rtnval = y.toString().padStart(3, '0');
|
||||||
for (let x = 0; x < secondArray.length; x++) {
|
const kiscode = firstArray[i] + secondArray[x] + rtnval;
|
||||||
for (let y = 0; y < 1000; y++) {
|
const url = `${baseUrl}${kiscode}`;
|
||||||
const rtnval = y.toString().padStart(3, '0');
|
try {
|
||||||
const kiscode = firstArray[i] + secondArray[x] + rtnval;
|
const startTime = Date.now(); // 시작 시간 저장
|
||||||
const url = `${baseUrl}${kiscode}`;
|
|
||||||
try {
|
|
||||||
const startTime = Date.now(); // 시작 시간 저장
|
|
||||||
|
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Request failed: ${response.statusText}`);
|
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();
|
main();
|
||||||
Loading…
x
Reference in New Issue
Block a user