From 0467b324d5955765de34aed044ac9da9a7cca022 Mon Sep 17 00:00:00 2001 From: Lee sang Yeop Date: Fri, 13 Oct 2023 19:15:12 +0900 Subject: [PATCH 1/4] =?UTF-8?q?Feat:=20=EC=9B=A8=EC=9D=BC=EB=B9=84=20?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EB=B8=94=EC=97=90=20link=20=EC=BB=AC?= =?UTF-8?q?=EB=9F=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/table/createTables.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/db/table/createTables.ts b/src/db/table/createTables.ts index 7a010496..758cde14 100644 --- a/src/db/table/createTables.ts +++ b/src/db/table/createTables.ts @@ -107,7 +107,8 @@ const createWhalebeDataTable = () => { id INT PRIMARY KEY AUTO_INCREMENT, title VARCHAR(255) NOT NULL UNIQUE, date VARCHAR(255) NOT NULL, - imgUrl VARCHAR(255) NOT NULL + imgUrl VARCHAR(255) NOT NULL, + link VARCHAR(255) NOT NULL );`; db.query(createTableQuery, (error) => { From 9793cf9ae3cd1bf6c6912d1694c92dce0a62d0ac Mon Sep 17 00:00:00 2001 From: Lee sang Yeop Date: Fri, 13 Oct 2023 19:16:03 +0900 Subject: [PATCH 2/4] =?UTF-8?q?Feat:=20=EC=9B=A8=EC=9D=BC=EB=B9=84=20?= =?UTF-8?q?=ED=81=AC=EB=A1=A4=EB=A7=81=20=EC=8B=9C=20URL=20=EB=A7=81?= =?UTF-8?q?=ED=81=AC=EB=8F=84=20=ED=81=AC=EB=A1=A4=EB=A7=81=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/crawling/whalebeCrawling.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/crawling/whalebeCrawling.ts b/src/crawling/whalebeCrawling.ts index aaa5d8f9..6e7e08a5 100644 --- a/src/crawling/whalebeCrawling.ts +++ b/src/crawling/whalebeCrawling.ts @@ -5,8 +5,18 @@ export interface WhalebeData { title: string; date: string; imgUrl: string; + link: string; } +const sliceURL = (link: string): string => { + if (link.startsWith('location.href=')) { + link = link.slice(15); + link = link.slice(0, -2); + } + + return link; +}; + export const whalebeCrawling = async (): Promise => { const hostname = 'https://whalebe.pknu.ac.kr'; const whalebeLink = hostname + '/main'; @@ -20,7 +30,8 @@ export const whalebeCrawling = async (): Promise => { programs.each((_, element) => { const imgUrl = hostname + $(element).find('img').attr('src'); - const title = $(element).find('.card-title').text(); + const link = hostname + sliceURL($(element).find('div').attr('onclick')); + const title = $(element).find('.card-title').text().trim(); const date = $(element) .find('.app_date') .find('.col-12') @@ -32,6 +43,7 @@ export const whalebeCrawling = async (): Promise => { title, date, imgUrl, + link, }; whalebeData.push(tmpData); }); From 48f4d34fa2ddea73e535dde7cb58eb503b651c3a Mon Sep 17 00:00:00 2001 From: Lee sang Yeop Date: Fri, 13 Oct 2023 19:16:30 +0900 Subject: [PATCH 3/4] =?UTF-8?q?Feat:=20=ED=95=B8=EB=93=A4=EB=9F=AC?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=ED=81=AC=EB=A1=A4=EB=A7=81=EB=90=9C=20URL?= =?UTF-8?q?=20=EB=A7=81=ED=81=AC=EB=A5=BC=20DB=20=EC=97=90=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/data/noticeHandler.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/db/data/noticeHandler.ts b/src/db/data/noticeHandler.ts index 7764eb52..93a256c5 100644 --- a/src/db/data/noticeHandler.ts +++ b/src/db/data/noticeHandler.ts @@ -219,11 +219,12 @@ export const saveSchoolNoticeToDB = async (): Promise => { }; export const saveWhalebeToDB = async (): Promise => { - const query = 'INSERT INTO 웨일비 (title, date, imgUrl) VALUES (?, ?, ?)'; + const query = + 'INSERT INTO 웨일비 (title, date, imgUrl, link) VALUES (?, ?, ?, ?)'; const whalebeDatas = await whalebeCrawling(); const promises = whalebeDatas.map((data) => { - const values = [data.title, data.date, data.imgUrl]; + const values = [data.title, data.date, data.imgUrl, data.link]; return new Promise((resolve) => { db.query(query, values, () => { From 26e3c5d775c689613827d039d33fb777cdf93063 Mon Sep 17 00:00:00 2001 From: Lee sang Yeop Date: Fri, 13 Oct 2023 19:23:20 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Feat:=20=EC=84=9C=EB=B2=84=20=EC=B5=9C?= =?UTF-8?q?=EC=B4=88=20=EC=8B=A4=ED=96=89=20=EC=8B=9C=20=EA=B8=B0=EC=A1=B4?= =?UTF-8?q?=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=9B=A8=EC=9D=BC=EB=B9=84=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=A5=BC=20=EC=A7=80=EC=9A=B0?= =?UTF-8?q?=EA=B3=A0=20=EC=83=88=EB=A1=9C=EC=9A=B4=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EC=B6=94=EA=B0=80=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 81bdce5f..ede28fde 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ import subscriptionRouter from '@apis/subscribe/controller'; import suggestionRouter from '@apis/suggestion/controller'; import env from '@config'; import { saveLanguageNoticeToDB } from '@db/data/languageHandler'; +import { saveWhalebeToDB } from '@db/data/noticeHandler'; import db from '@db/index'; import { corsOptions } from '@middlewares/cors'; import errorHandler from '@middlewares/error-handler'; @@ -12,6 +13,7 @@ import cors from 'cors'; import express, { Request, Response } from 'express'; import morgan from 'morgan'; import webpush from 'src/config/webpush'; +import notificationToSlack from 'src/hooks/notificateToSlack'; import { initialCrawling } from 'src/hooks/startCrawlingData'; import './hooks/cronNoticeCrawling'; @@ -42,7 +44,7 @@ app.listen(env.SERVER_PORT, () => { webpush(); -const handleDeployToServer = () => { +const handleDeployToServer = async () => { // 이 함수는 현재 배포되어있는 서버를 위해 사용되는 로직이며 최초 서버에 배포되는 1회만 실행되도록 하기위한 함수에요 // 그렇기에 아래에 작성된 코드들은 배포서버에 배포되면 다음 배포전 수정해주세요!! @@ -67,6 +69,20 @@ const handleDeployToServer = () => { }; createLanguageDataTable(); + + const addColumnQuery = `ALTER TABLE 웨일비 ADD link VARCHAR(255)`; + db.query(addColumnQuery, (err) => { + if (err) { + notificationToSlack('배포시 최초 핸들러 함수 에러'); + return; + } + const query = `delete from 웨일비;`; + db.query(query, (err) => { + if (!err) { + saveWhalebeToDB(); + } + }); + }); }; handleDeployToServer();