Skip to content

Commit

Permalink
Merge pull request #149 from GDSC-PKNU-Official/feat/#148
Browse files Browse the repository at this point in the history
Feat/#148: 웨일비 데이터 크롤링 시 모집기간과 운영기간을 크롤링 해 DB에 저장하도록 추가
  • Loading branch information
pp449 authored Dec 1, 2023
2 parents 9f87751 + c6cf984 commit df957e0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/@types/college.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export type NoticeBoolean = 1 | 0;

export interface WhalebeData {
title: string;
date: string;
imgUrl: string;
operating_period: string;
recruitment_period: string;
imgurl: string;
link: string;
}
5 changes: 4 additions & 1 deletion src/apis/notice/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ export const getWhalebe = async (): Promise<WhalebeData[]> => {
).padStart(2, '0')}.${String(today.getDate()).padStart(2, '0')}`;

const filteredData = whalebeData
.filter((data) => data.date >= todayString)
.filter(
(data) =>
data.recruitment_period.split('~')[1].trim() >= todayString || data,
)
.slice(0, 7);
return filteredData;
} catch (error) {
Expand Down
35 changes: 21 additions & 14 deletions src/crawling/whalebeCrawling.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import axios from 'axios';
import * as cheerio from 'cheerio';

export interface WhalebeData {
title: string;
date: string;
imgUrl: string;
link: string;
}
import { WhalebeData } from 'src/@types/college';

const sliceURL = (link: string): string => {
if (link.startsWith('location.href=')) {
Expand All @@ -29,20 +23,33 @@ export const whalebeCrawling = async (): Promise<WhalebeData[]> => {
if (programs.length < 1) return;

programs.each((_, element) => {
const imgUrl = hostname + $(element).find('img').attr('src');
const imgurl = hostname + $(element).find('img').attr('src');
const link = hostname + sliceURL($(element).find('div').attr('onclick'));
const title = $(element).find('.card-title').text().trim();
const date = $(element)
const recruitment_period = $(element)
.find('.app_date')
.find('.col-12')
.first()
.find('span')
.eq(1)
.text()
.split('~')[1]
.trim();
const tmpData = {
.trim()
.replace('&nbsp;', '');
const operating_period = $(element)
.find('.app_date')
.find('.col-12')
.eq(1)
.find('span')
.eq(1)
.text()
.trim()
.replace('&nbsp;', '');

const tmpData: WhalebeData = {
title,
date,
imgUrl,
recruitment_period,
operating_period,
imgurl,
link,
};
whalebeData.push(tmpData);
Expand Down
8 changes: 7 additions & 1 deletion src/db/data/noticeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,13 @@ export const saveWhalebeToDB = async (): Promise<void> => {

// TODO: 웨일비 크롤링하는 데이터 추가해야함
const promises = whalebeDatas.map((data) => {
const values = [data.title, data.link, 'tmp', 'tmp2', data.imgUrl];
const values = [
data.title,
data.link,
data.operating_period,
data.recruitment_period,
data.imgurl,
];

return db.execute(query, values);
});
Expand Down

0 comments on commit df957e0

Please sign in to comment.