diff --git a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/crawlhandler/parser/PpomppuArticleParserV2.java b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/crawlhandler/parser/PpomppuArticleParserV2.java index d8644b9..455bc8d 100644 --- a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/crawlhandler/parser/PpomppuArticleParserV2.java +++ b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/crawlhandler/parser/PpomppuArticleParserV2.java @@ -23,8 +23,10 @@ import java.util.regex.Pattern; @Component public class PpomppuArticleParserV2 { - private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yy.MM.dd HH:mm:ss") - .withZone(ZoneId.of("Asia/Seoul")); + static { + DateTimeFormatter.ofPattern("yy.MM.dd HH:mm:ss") + .withZone(ZoneId.of("Asia/Seoul")); + } public List
parse(String html) { Elements trElements = converHtmlToTrElements(html); @@ -64,8 +66,8 @@ public class PpomppuArticleParserV2 { Elements tdList = tr.getElementsByTag("td"); Long articleId = Long.parseLong(tdList.get(0).text()); - String title = tdList.get(2).text(); - String articleUrl = parseArticleUrl(tdList.get(2).getElementsByTag("a").attr("href")); + String title = tdList.get(1).text(); + String articleUrl = parseArticleUrl(tdList.get(1).getElementsByTag("a").attr("href")); String boardName = parseBoardName(title); Integer recommended = parseRecommended(tdList.get(4)); Integer hit = NumberUtils.parseInt(tdList.get(5).text(), 0); diff --git a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/event/handler/ArticleUpsertEventListener.java b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/event/handler/ArticleUpsertEventListener.java index 924353a..f6a8189 100644 --- a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/event/handler/ArticleUpsertEventListener.java +++ b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/event/handler/ArticleUpsertEventListener.java @@ -7,6 +7,7 @@ import com.myoa.engineering.crawl.shopping.domain.model.v2.SubscribedKeywordAggr import com.myoa.engineering.crawl.shopping.event.ArticleUpsertEvent; import com.myoa.engineering.crawl.shopping.service.AppUserQueryService; import com.myoa.engineering.crawl.shopping.service.SubscribedKeywordCacheService; +import com.myoa.engineering.crawl.shopping.service.slack.SlackMessageBlockService; import com.myoa.engineering.crawl.shopping.service.slack.UserNotifyService; import com.myoa.engineering.crawl.shopping.support.dto.constant.CrawlTarget; import com.myoa.engineering.crawl.shopping.util.SlackMessageUtils; @@ -26,13 +27,16 @@ public class ArticleUpsertEventListener { private final SubscribedKeywordCacheService subscribedKeywordCacheService; private final AppUserQueryService appUserQueryService; private final UserNotifyService userNotifyService; - + private final SlackMessageBlockService slackMessageBlockService; public ArticleUpsertEventListener(SubscribedKeywordCacheService subscribedKeywordCacheService, - AppUserQueryService appUserQueryService, UserNotifyService userNotifyService) { + AppUserQueryService appUserQueryService, + UserNotifyService userNotifyService, + SlackMessageBlockService slackMessageBlockService) { this.subscribedKeywordCacheService = subscribedKeywordCacheService; this.appUserQueryService = appUserQueryService; this.userNotifyService = userNotifyService; + this.slackMessageBlockService = slackMessageBlockService; } @@ -85,13 +89,13 @@ public class ArticleUpsertEventListener { .collect(Collectors.joining("\n")); ChatPostMessageRequest request = - userNotifyService.generateMessage() - .blocks(Blocks.asBlocks( - SlackMessageUtils.ofHeader(crawlTarget.getAlias()), - SlackMessageUtils.ofSection(composited), - SlackMessageUtils.ofDivider() - )) - .build(); + slackMessageBlockService.generateMessage() + .blocks(Blocks.asBlocks( + SlackMessageUtils.ofHeader(crawlTarget.getAlias()), + SlackMessageUtils.ofSection(composited), + SlackMessageUtils.ofDivider() + )) + .build(); return userNotifyService.notify(request); } @@ -103,11 +107,11 @@ public class ArticleUpsertEventListener { } ChatPostMessageRequest request = - userNotifyService.generateMessage() - .blocks(Blocks.asBlocks( - SlackMessageUtils.ofSection(userNotifyModel.toCompositedMessage()) - )) - .build(); + slackMessageBlockService.generateMessage() + .blocks(Blocks.asBlocks( + SlackMessageUtils.ofSection(userNotifyModel.toCompositedMessage()) + )) + .build(); userNotifyService.notify(request); } diff --git a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/service/slack/LocalUserNotifyService.java b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/service/slack/LocalUserNotifyService.java new file mode 100644 index 0000000..7e9e9db --- /dev/null +++ b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/service/slack/LocalUserNotifyService.java @@ -0,0 +1,20 @@ +package com.myoa.engineering.crawl.shopping.service.slack; + +import com.slack.api.methods.request.chat.ChatPostMessageRequest; +import com.slack.api.methods.response.chat.ChatPostMessageResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Service; + +@Slf4j +@Profile("local") +@Service +public class LocalUserNotifyService implements UserNotifyService { + + @Override + public ChatPostMessageResponse notify(ChatPostMessageRequest request) { + log.info("Request: {}", request); + return new ChatPostMessageResponse(); + } + +} diff --git a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/service/slack/SlackMessageBlockService.java b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/service/slack/SlackMessageBlockService.java new file mode 100644 index 0000000..86d1543 --- /dev/null +++ b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/service/slack/SlackMessageBlockService.java @@ -0,0 +1,24 @@ +package com.myoa.engineering.crawl.shopping.service.slack; + +import com.myoa.engineering.crawl.shopping.configuration.slack.properties.SlackSecretProperties; +import com.slack.api.methods.request.chat.ChatPostMessageRequest; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +public class SlackMessageBlockService { + private static final String SLACK_PROPERTIES_UNIT_NAME = "shopping-crawler"; + + private final SlackSecretProperties.SlackSecretPropertiesUnit slackSecretProperties; + + public SlackMessageBlockService(SlackSecretProperties slackSecretProperties) { + this.slackSecretProperties = slackSecretProperties.find(SLACK_PROPERTIES_UNIT_NAME); + } + + public ChatPostMessageRequest.ChatPostMessageRequestBuilder generateMessage() { + return ChatPostMessageRequest.builder() + .channel(slackSecretProperties.getChannel()) + .username(slackSecretProperties.getUsername()); + } +} diff --git a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/service/slack/UserNotifyService.java b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/service/slack/UserNotifyService.java index f751acc..9a0344f 100644 --- a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/service/slack/UserNotifyService.java +++ b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/service/slack/UserNotifyService.java @@ -1,41 +1,8 @@ package com.myoa.engineering.crawl.shopping.service.slack; -import com.myoa.engineering.crawl.shopping.configuration.slack.properties.SlackSecretProperties; -import com.slack.api.methods.MethodsClient; import com.slack.api.methods.request.chat.ChatPostMessageRequest; import com.slack.api.methods.response.chat.ChatPostMessageResponse; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -@Slf4j -@Service -public class UserNotifyService { - - private static final String SLACK_PROPERTIES_UNIT_NAME = "shopping-crawler"; - - private final SlackSecretProperties.SlackSecretPropertiesUnit slackSecretProperties; - private final MethodsClient methodsClient; - - public UserNotifyService(SlackSecretProperties slackSecretProperties, - MethodsClient methodsClient) { - this.slackSecretProperties = slackSecretProperties.find(SLACK_PROPERTIES_UNIT_NAME); - this.methodsClient = methodsClient; - } - - public ChatPostMessageResponse notify(ChatPostMessageRequest request) { - try { - return methodsClient.chatPostMessage(request); - } catch (Exception e) { - log.warn("Failed. message: {}", request, e); - ChatPostMessageResponse response = new ChatPostMessageResponse(); - response.setOk(false); - return response; - } - } - - public ChatPostMessageRequest.ChatPostMessageRequestBuilder generateMessage() { - return ChatPostMessageRequest.builder() - .channel(slackSecretProperties.getChannel()) - .username(slackSecretProperties.getUsername()); - } +public interface UserNotifyService { + ChatPostMessageResponse notify(ChatPostMessageRequest request); } diff --git a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/service/slack/UserNotifyServiceImpl.java b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/service/slack/UserNotifyServiceImpl.java new file mode 100644 index 0000000..8ecbdc2 --- /dev/null +++ b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/service/slack/UserNotifyServiceImpl.java @@ -0,0 +1,35 @@ +package com.myoa.engineering.crawl.shopping.service.slack; + +import com.slack.api.methods.MethodsClient; +import com.slack.api.methods.request.chat.ChatPostMessageRequest; +import com.slack.api.methods.response.chat.ChatPostMessageResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Service; + +@Slf4j +@Profile("!local") +@Service +public class UserNotifyServiceImpl implements UserNotifyService { + + + private final MethodsClient methodsClient; + + public UserNotifyServiceImpl(MethodsClient methodsClient) { + this.methodsClient = methodsClient; + } + + @Override + public ChatPostMessageResponse notify(ChatPostMessageRequest request) { + try { + return methodsClient.chatPostMessage(request); + } catch (Exception e) { + log.warn("Failed. message: {}", request, e); + ChatPostMessageResponse response = new ChatPostMessageResponse(); + response.setOk(false); + return response; + } + } + + +} diff --git a/shopping-crawler/src/main/resources/application-dev.yml b/shopping-crawler/src/main/resources/application-dev.yml new file mode 100644 index 0000000..23fba97 --- /dev/null +++ b/shopping-crawler/src/main/resources/application-dev.yml @@ -0,0 +1,18 @@ +spring: + config: + activate: + on-profile: local + import: + - classpath:/datasource/dev.yml + - classpath:/slack/dev.yml + +server: + port: 20080 + + # import: optional:configserver:http://localhost:11080 # can be start up even config server was not found. + +feign: + client: + config: + default: + loggerLevel: FULL \ No newline at end of file