모락 api 삭제
This commit is contained in:
parent
26417866db
commit
2c6b8b634f
@ -1,21 +0,0 @@
|
||||
package com.itn.mjonApi.etc.webPageCrawling.morak.service;
|
||||
|
||||
import com.itn.mjonApi.cmn.msg.RestResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* packageName : com.itn.mjonApi.etc.ganpandaum.service
|
||||
* fileName : GdService
|
||||
* author : hylee
|
||||
* date : 2023-06-07
|
||||
* description :
|
||||
* ===========================================================
|
||||
* DATE AUTHOR NOTE
|
||||
* -----------------------------------------------------------
|
||||
* 2023-06-07 hylee 최초 생성
|
||||
*/
|
||||
public interface MorakService {
|
||||
RestResponse morakMenu() throws IOException;
|
||||
// void morakMenu() throws IOException;
|
||||
}
|
||||
@ -1,105 +0,0 @@
|
||||
package com.itn.mjonApi.etc.webPageCrawling.morak.service.impl;
|
||||
|
||||
import com.itn.mjonApi.cmn.msg.RestResponse;
|
||||
import com.itn.mjonApi.etc.webPageCrawling.morak.service.MorakService;
|
||||
import com.itn.mjonApi.util.slack.SlackUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* packageName : com.itn.mjonApi.etc.ganpandaum.service.impl
|
||||
* fileName : GdServiceImpl
|
||||
* author : hylee
|
||||
* date : 2023-06-07
|
||||
* description :
|
||||
* ===========================================================
|
||||
* DATE AUTHOR NOTE
|
||||
* -----------------------------------------------------------
|
||||
* 2023-06-07 hylee 최초 생성
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class MorakServiceImpl implements MorakService {
|
||||
|
||||
@Override
|
||||
public RestResponse morakMenu() {
|
||||
// public void morakMenu() {
|
||||
String imgUrl = "";
|
||||
try {
|
||||
while (true){
|
||||
// 웹사이트에 연결
|
||||
Document doc = Jsoup.connect("https://m.blog.naver.com/goodchild71/222831407207").get();
|
||||
|
||||
// img가 있는 태그 가져오기
|
||||
Element mainDoc = doc.select(".se-main-container").first();
|
||||
|
||||
// img에서 큰사이즈의 이미지 URL 가져오기
|
||||
imgUrl = mainDoc.select("img").attr("data-lazy-src");
|
||||
|
||||
// 현재 날짜와 비교
|
||||
// true면 오늘 날짜가 맞음
|
||||
if(this.dateComparison(imgUrl)){
|
||||
SlackUtil.sendMorakMenuToSlack(imgUrl);
|
||||
break;
|
||||
}else{
|
||||
|
||||
// 11시 30분이 지났으면 break;
|
||||
if(isCurrentTime1130()){
|
||||
break;
|
||||
}
|
||||
|
||||
Thread.sleep(100000);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
return new RestResponse(imgUrl);
|
||||
|
||||
}
|
||||
|
||||
private boolean isCurrentTime1130() {
|
||||
LocalTime now = LocalTime.now();
|
||||
LocalTime targetTime = LocalTime.of(11, 30);
|
||||
return now.isAfter(targetTime);
|
||||
}
|
||||
|
||||
private Boolean dateComparison(String imgUrl) {
|
||||
Boolean result = false;
|
||||
// imgUrl에서 추출할 날짜 패턴 정수 8개 설정
|
||||
Pattern pattern = Pattern.compile("(\\d{8})");
|
||||
// 날짜 패턴 추출
|
||||
Matcher matcher = pattern.matcher(imgUrl);
|
||||
|
||||
// 찾았으면 if true
|
||||
if (matcher.find()) {
|
||||
String extractedDate = matcher.group(1);
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||
LocalDate dateFromText = LocalDate.parse(extractedDate, formatter);
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
|
||||
if (dateFromText.equals(currentDate)) {
|
||||
result = true;
|
||||
}
|
||||
} else {
|
||||
System.out.println("No date found in the text.");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
package com.itn.mjonApi.etc.webPageCrawling.morak.web;
|
||||
|
||||
import com.itn.mjonApi.cmn.msg.RestResponse;
|
||||
import com.itn.mjonApi.etc.webPageCrawling.morak.service.MorakService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* packageName : com.itn.mjonApi.etc.ganpandaum.web
|
||||
* fileName : SendRestController
|
||||
* author : hylee
|
||||
* date : 2023-02-15
|
||||
* description :
|
||||
* ===========================================================
|
||||
* DATE AUTHOR NOTE
|
||||
* -----------------------------------------------------------
|
||||
* 2023-02-15 hylee 최초 생성
|
||||
*/
|
||||
|
||||
// 치환문자가 있으면 , => §로 치환
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class MorakController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private MorakService morakService;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @Discription 모락 메뉴 크롤링 컨트롤러
|
||||
* @return
|
||||
*/
|
||||
@CrossOrigin("*") // 모든 요청에 접근 허용
|
||||
@GetMapping("/etc/morak/morakMenu")
|
||||
// public void morakMenu() throws Exception {
|
||||
// log.info("morakMenu morakMenu morakMenu");
|
||||
// morakService.morakMenu();
|
||||
// }
|
||||
public ResponseEntity<RestResponse> morakMenu() throws Exception {
|
||||
return ResponseEntity.ok().body(morakService.morakMenu());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,6 +1,5 @@
|
||||
package com.itn.mjonApi.util.scheduled;
|
||||
|
||||
import com.itn.mjonApi.etc.webPageCrawling.morak.service.MorakService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -21,12 +20,12 @@ import java.io.IOException;
|
||||
@Service
|
||||
public class ScheduledTasks {
|
||||
|
||||
@Autowired
|
||||
private MorakService morakService;
|
||||
// @Autowired
|
||||
// private MorakService morakService;
|
||||
|
||||
@Scheduled(cron = "0 40 10 * * MON-FRI")
|
||||
public void noonJob() throws IOException {
|
||||
System.out.println("It's noon!");
|
||||
morakService.morakMenu();
|
||||
}
|
||||
// @Scheduled(cron = "0 40 10 * * MON-FRI")
|
||||
// public void noonJob() throws IOException {
|
||||
// System.out.println("It's noon!");
|
||||
// morakService.morakMenu();
|
||||
// }
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user