From aff1e361d6f6985b0c05da60dd5cf7e5dc204158 Mon Sep 17 00:00:00 2001 From: Lee sang Yeop Date: Wed, 11 Oct 2023 19:47:56 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Fix:=20=EA=B3=B5=EA=B0=84=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=EC=8B=9C=EC=8A=A4=ED=85=9C=EA=B3=B5=ED=95=99=EA=B3=BC=EB=8A=94?= =?UTF-8?q?=202=ED=8E=98=EC=9D=B4=EC=A7=80=EA=B9=8C=EC=A7=80=20=ED=81=AC?= =?UTF-8?q?=EB=A1=A4=EB=A7=81=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/crawling/noticeCrawling.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/crawling/noticeCrawling.ts b/src/crawling/noticeCrawling.ts index 49341ca8..b2c8a76f 100644 --- a/src/crawling/noticeCrawling.ts +++ b/src/crawling/noticeCrawling.ts @@ -74,6 +74,14 @@ export const noticeListCrawling = async ( const pinnedNotice: string[] = []; const normalNotice: string[] = []; + if (link === 'http://geoinfo.pknu.ac.kr/05piazza/08.php') { + const noticePage2Link = + 'http://geoinfo.pknu.ac.kr/05piazza/08.php?p=2&key=&keyword=&bbscode=cate0501&reCategory='; + const noticePage2Lists = await noticeListCrawling(noticePage2Link, link); + pinnedNotice.push(...noticePage2Lists.pinnedNotice); + normalNotice.push(...noticePage2Lists.normalNotice); + } + tableData.each((index, element) => { const anchorElement = $(element).find('a'); let tmpLink = anchorElement.attr('href'); @@ -86,7 +94,7 @@ export const noticeListCrawling = async ( .text() .match(/\d{4}[-.]\d{2}[-.]\d{2}/); - if (link === 'http://geoinfo.pknu.ac.kr/05piazza/08.php') { + if (link.startsWith('http://geoinfo.pknu.ac.kr/05piazza/08.php')) { // 공간정보시스템공학과 if ($(element).find('td').first().text().trim() === '공지') pinnedNotice.push(tmpLink); From 524c95bfb9e937411af3eb9c60456527900f8963 Mon Sep 17 00:00:00 2001 From: Lee sang Yeop Date: Wed, 11 Oct 2023 20:13:02 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Fix:=20=EA=B3=A0=EC=A0=95=20=EA=B3=B5?= =?UTF-8?q?=EC=A7=80=EC=82=AC=ED=95=AD=20=EB=82=B4=EB=A0=A4=EA=B0=80?= =?UTF-8?q?=EB=A9=B4=20DB=EC=97=90=EC=84=9C=20=EC=82=AD=EC=A0=9C=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/data/noticeHandler.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/db/data/noticeHandler.ts b/src/db/data/noticeHandler.ts index 7764eb52..16fddb83 100644 --- a/src/db/data/noticeHandler.ts +++ b/src/db/data/noticeHandler.ts @@ -50,6 +50,15 @@ const saveNotice = (notice: Notice, major: string): Promise => { }); }; +const deleteNotice = (major: string, noticeLinks: string[], mode: string) => { + const deleteQuery = `DELETE FROM ${major}${mode} WHERE link = ?`; + for (const link of noticeLinks) { + db.query(deleteQuery, [link], (err) => { + if (err) notificationToSlack(`${major}${mode} 공지사항 삭제 실패`); + }); + } +}; + export const saveNoticeToDB = async (): Promise => { const selectQuery = 'SELECT * FROM departments;'; const results = await new Promise((resolve) => { @@ -97,6 +106,7 @@ export const saveNoticeToDB = async (): Promise => { return; } const rows = res as RowDataPacket[]; + const deleteNotiLinks: string[] = []; let pinnedNotiLink: string[] = []; if (Array.isArray(rows) && rows.length > 0) @@ -112,6 +122,13 @@ export const saveNoticeToDB = async (): Promise => { savePromises.push(saveNotice(result, major + '고정')); } } + + for (const noticeLink of pinnedNotiLink) { + if (!noticeLists.pinnedNotice.includes(noticeLink)) { + deleteNotiLinks.push(noticeLink); + } + } + deleteNotice(major, deleteNotiLinks, '고정'); }); } From 80c5faf5e5c268fe19cdc09d89f6bc08c2c2e573 Mon Sep 17 00:00:00 2001 From: Lee sang Yeop Date: Wed, 11 Oct 2023 20:13:40 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Fix:=20=ED=98=84=EC=9E=AC=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=A3=BC=EC=84=9D=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/src/index.ts b/src/index.ts index 81bdce5f..ef7507a6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,28 +45,6 @@ webpush(); const handleDeployToServer = () => { // 이 함수는 현재 배포되어있는 서버를 위해 사용되는 로직이며 최초 서버에 배포되는 1회만 실행되도록 하기위한 함수에요 // 그렇기에 아래에 작성된 코드들은 배포서버에 배포되면 다음 배포전 수정해주세요!! - - // 어학 관련 테이블 생성 후 데이터 삽입 - const createLanguageDataTable = () => { - const createTableQuery = `CREATE TABLE 어학공지 ( - id INT PRIMARY KEY AUTO_INCREMENT, - title VARCHAR(255) NOT NULL, - link VARCHAR(255) NOT NULL UNIQUE, - uploadDate VARCHAR(255) NOT NULL - );`; - - db.query(createTableQuery, async (error) => { - if (error) { - console.log('어학 DB 생성 실패', error); - return; - } - - console.log('어학 테이블 생성 성공!'); - await saveLanguageNoticeToDB(); - }); - }; - - createLanguageDataTable(); }; -handleDeployToServer(); +// handleDeployToServer();