Skip to content

Commit

Permalink
Merge pull request #20 from kjungw1025/fix/cafeteria
Browse files Browse the repository at this point in the history
fix: 학식 양식 일부 변경으로 인한 학식 크롤링 코드 수정
  • Loading branch information
kjungw1025 authored Mar 6, 2024
2 parents 7aa6660 + 0b47e25 commit 91b00de
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
Expand All @@ -28,6 +29,9 @@
@EnableScheduling
public class DkuCafeteriaService {

@Value("${dku.cafeteria.api-path}")
private String url;

private final CafeteriaRepository cafeteriaRepository;
private final CafeteriaInfoRepository cafeteriaInfoRepository;
private String breakfastResult;
Expand All @@ -47,7 +51,6 @@ public class DkuCafeteriaService {

@Transactional
public void crawlCafeteria() {
String url = "${dku.cafeteria.api-path}";

try {
LocalDate today = LocalDate.now();
Expand Down Expand Up @@ -113,6 +116,19 @@ public void crawlCafeteria() {

// [A코스] 있는지 탐색
Boolean breakfastAFlag = parseCourseA(breakfast, "BRE", breakfastAcourseList, breakfastBcourseList);
if (!breakfastAFlag) {

// 하나의 식단만 존재할 때, [A코스]라고 명시하지 않는 경우가 존재함
StringBuilder sb = new StringBuilder();
for (int k = 0; k < breakfast.length(); k++) {
char c = breakfast.charAt(k);
if (c == '\\') {
sb.append('\n');
}
sb.append(c);
}
breakfastResult = String.valueOf(sb);
}

// [B코스] 있는지 탐색
Boolean breakfastBFlag = parseCourseB(breakfast, "BRE", breakfastBcourseList, breakfastCcourseList, breakfastAFlag);
Expand Down Expand Up @@ -230,7 +246,6 @@ private Boolean parseCourseA(String meal,
}
}
else { // [A코스]가 없는 경우
addMealResult(mealType, notOperated.get(mealType));
flag = false;
}
return flag;
Expand Down

0 comments on commit 91b00de

Please sign in to comment.