[NO-ISSUE] React ppomppu

This commit is contained in:
woozu-shin 2024-06-04 09:37:33 +09:00
parent 0365f64984
commit 25b3dd7867
7 changed files with 123 additions and 53 deletions

View File

@ -23,8 +23,10 @@ import java.util.regex.Pattern;
@Component @Component
public class PpomppuArticleParserV2 { public class PpomppuArticleParserV2 {
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yy.MM.dd HH:mm:ss") static {
DateTimeFormatter.ofPattern("yy.MM.dd HH:mm:ss")
.withZone(ZoneId.of("Asia/Seoul")); .withZone(ZoneId.of("Asia/Seoul"));
}
public List<Article> parse(String html) { public List<Article> parse(String html) {
Elements trElements = converHtmlToTrElements(html); Elements trElements = converHtmlToTrElements(html);
@ -64,8 +66,8 @@ public class PpomppuArticleParserV2 {
Elements tdList = tr.getElementsByTag("td"); Elements tdList = tr.getElementsByTag("td");
Long articleId = Long.parseLong(tdList.get(0).text()); Long articleId = Long.parseLong(tdList.get(0).text());
String title = tdList.get(2).text(); String title = tdList.get(1).text();
String articleUrl = parseArticleUrl(tdList.get(2).getElementsByTag("a").attr("href")); String articleUrl = parseArticleUrl(tdList.get(1).getElementsByTag("a").attr("href"));
String boardName = parseBoardName(title); String boardName = parseBoardName(title);
Integer recommended = parseRecommended(tdList.get(4)); Integer recommended = parseRecommended(tdList.get(4));
Integer hit = NumberUtils.parseInt(tdList.get(5).text(), 0); Integer hit = NumberUtils.parseInt(tdList.get(5).text(), 0);

View File

@ -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.event.ArticleUpsertEvent;
import com.myoa.engineering.crawl.shopping.service.AppUserQueryService; import com.myoa.engineering.crawl.shopping.service.AppUserQueryService;
import com.myoa.engineering.crawl.shopping.service.SubscribedKeywordCacheService; 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.service.slack.UserNotifyService;
import com.myoa.engineering.crawl.shopping.support.dto.constant.CrawlTarget; import com.myoa.engineering.crawl.shopping.support.dto.constant.CrawlTarget;
import com.myoa.engineering.crawl.shopping.util.SlackMessageUtils; import com.myoa.engineering.crawl.shopping.util.SlackMessageUtils;
@ -26,13 +27,16 @@ public class ArticleUpsertEventListener {
private final SubscribedKeywordCacheService subscribedKeywordCacheService; private final SubscribedKeywordCacheService subscribedKeywordCacheService;
private final AppUserQueryService appUserQueryService; private final AppUserQueryService appUserQueryService;
private final UserNotifyService userNotifyService; private final UserNotifyService userNotifyService;
private final SlackMessageBlockService slackMessageBlockService;
public ArticleUpsertEventListener(SubscribedKeywordCacheService subscribedKeywordCacheService, public ArticleUpsertEventListener(SubscribedKeywordCacheService subscribedKeywordCacheService,
AppUserQueryService appUserQueryService, UserNotifyService userNotifyService) { AppUserQueryService appUserQueryService,
UserNotifyService userNotifyService,
SlackMessageBlockService slackMessageBlockService) {
this.subscribedKeywordCacheService = subscribedKeywordCacheService; this.subscribedKeywordCacheService = subscribedKeywordCacheService;
this.appUserQueryService = appUserQueryService; this.appUserQueryService = appUserQueryService;
this.userNotifyService = userNotifyService; this.userNotifyService = userNotifyService;
this.slackMessageBlockService = slackMessageBlockService;
} }
@ -85,7 +89,7 @@ public class ArticleUpsertEventListener {
.collect(Collectors.joining("\n")); .collect(Collectors.joining("\n"));
ChatPostMessageRequest request = ChatPostMessageRequest request =
userNotifyService.generateMessage() slackMessageBlockService.generateMessage()
.blocks(Blocks.asBlocks( .blocks(Blocks.asBlocks(
SlackMessageUtils.ofHeader(crawlTarget.getAlias()), SlackMessageUtils.ofHeader(crawlTarget.getAlias()),
SlackMessageUtils.ofSection(composited), SlackMessageUtils.ofSection(composited),
@ -103,7 +107,7 @@ public class ArticleUpsertEventListener {
} }
ChatPostMessageRequest request = ChatPostMessageRequest request =
userNotifyService.generateMessage() slackMessageBlockService.generateMessage()
.blocks(Blocks.asBlocks( .blocks(Blocks.asBlocks(
SlackMessageUtils.ofSection(userNotifyModel.toCompositedMessage()) SlackMessageUtils.ofSection(userNotifyModel.toCompositedMessage())
)) ))

View File

@ -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();
}
}

View File

@ -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());
}
}

View File

@ -1,41 +1,8 @@
package com.myoa.engineering.crawl.shopping.service.slack; 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.request.chat.ChatPostMessageRequest;
import com.slack.api.methods.response.chat.ChatPostMessageResponse; import com.slack.api.methods.response.chat.ChatPostMessageResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j public interface UserNotifyService {
@Service ChatPostMessageResponse notify(ChatPostMessageRequest request);
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());
}
} }

View File

@ -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;
}
}
}

View File

@ -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