Skip to content

Commit 1d84fe9

Browse files
authored
Merge pull request #84 from Block-Guard/refactor/news-api
[Refactor] 핵심 키워드 뉴스 크롤링
2 parents fc0dce3 + fa2f578 commit 1d84fe9

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/main/java/com/blockguard/server/domain/news/scheduler/NewsSaveScheduler.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
import org.springframework.scheduling.annotation.Scheduled;
99
import org.springframework.stereotype.Component;
1010

11+
import java.util.EnumSet;
1112
import java.util.List;
1213
import java.util.Map;
14+
import java.util.Set;
1315

1416
@Component
1517
@Slf4j
@@ -25,7 +27,7 @@ public class NewsSaveScheduler {
2527
Map.entry(Category.LOAN_FRAUD, List.of("대출 사기", "저금리 대출 사기", "대출 빙자 사기")),
2628
Map.entry(Category.CARD_IMPERSONATION, List.of("카드사 사칭", "카드사 피싱", "신용카드 사칭")),
2729
Map.entry(Category.FAMILY_IMPERSONATION, List.of("가족 사칭", "지인 사칭")),
28-
Map.entry(Category.EVENT_IMPERSONATION, List.of("경조사 사칭", "경조사 문자 사기", "모바일 청첩장 사기", "부고장 스미싱","온라인 부고장 사기","청첩장 스미싱")),
30+
Map.entry(Category.EVENT_IMPERSONATION, List.of("경조사 사칭", "경조사 문자 사기", "모바일 청첩장 사기", "부고장 스미싱", "온라인 부고장 사기", "청첩장 스미싱")),
2931
Map.entry(Category.PUBLIC_IMPERSONATION, List.of("공공기관 사칭", "국세청 사칭", "경찰 출석 요구 사칭", "검찰 사칭", "과태료 사칭")),
3032
Map.entry(Category.PART_TIME_SCAM, List.of("알바 사기", "부업 사기", "구인 사기")),
3133
Map.entry(Category.GOVERNMENT_GRANT_SCAM, List.of("정부지원금 사기", "보조금 사기", "지원금 사칭")),
@@ -37,7 +39,11 @@ public class NewsSaveScheduler {
3739

3840
@Async
3941
public void crawlingForAdmin() {
40-
crawlAll();
42+
crawlByCategories(EnumSet.of(
43+
Category.VOICE_PHISHING,
44+
Category.SMISHING,
45+
Category.MESSAGE_VOICE_PHISHING
46+
));
4147
}
4248

4349
@Async
@@ -47,16 +53,22 @@ public void saveNewsArticles() {
4753
}
4854

4955
private void crawlAll() {
50-
log.info("뉴스 크롤링 스케줄링 시작");
51-
KEYWORDS_PER_CATEGORY.forEach((category, keywords) -> {
56+
crawlByCategories(KEYWORDS_PER_CATEGORY.keySet());
57+
}
58+
59+
private void crawlByCategories(Set<Category> categories) {
60+
log.info("뉴스 크롤링 시작 (targets={})", categories);
61+
categories.forEach(category -> {
62+
List<String> keywords = KEYWORDS_PER_CATEGORY.getOrDefault(category, List.of());
5263
for (String keyword : keywords) {
5364
try {
5465
daumNewsCrawler.fetchNewsFromDaum(keyword, category);
5566
} catch (Exception e) {
56-
log.warn("크롤 실패: category={}, keyword={}", category, keyword, e);
67+
log.warn("크롤링 실패: category={}, keyword={}", category, keyword, e);
5768
}
5869
}
5970
});
60-
log.info("뉴스 크롤링 스케줄링 완료");
71+
log.info("뉴스 크롤링 완료");
6172
}
73+
6274
}

0 commit comments

Comments
 (0)