Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#148: 웨일비 데이터 크롤링 시 모집기간과 운영기간을 크롤링 해 DB에 저장하도록 추가 #149

Merged
merged 4 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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