Compare commits
3 Commits
7b230fdb74
...
feature/PP
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d315e2a9f | ||
|
|
8eb431a812 | ||
|
|
520a651a70 |
@@ -6,7 +6,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'com.myoa.engineering.crawl.ppomppu'
|
||||
version = '1.0.3'
|
||||
version = '1.1.1'
|
||||
sourceCompatibility = '11'
|
||||
|
||||
configurations {
|
||||
@@ -21,7 +21,7 @@ repositories {
|
||||
|
||||
allprojects {
|
||||
group = 'com.myoa.engineering.crawl.ppomppu'
|
||||
version = '1.0.3'
|
||||
version = '1.1.1'
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'idea'
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.processor.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.domain.PpomppuArticle;
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.dto.FeedParsedResult;
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.service.MessageSenderService;
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.service.PpomppuArticleService;
|
||||
@@ -48,9 +51,20 @@ public class CrawlAPIController {
|
||||
.map(e -> ppomppuArticleService.filterOnlyNewArticles(boardName, e))
|
||||
.map(e -> ppomppuArticleService.save(boardName, e))
|
||||
.filter(e -> !e.isEmpty())
|
||||
.flatMap(messageSenderService::sendBlockMessageToSlack);
|
||||
.flatMap(e -> messageSenderService.sendBlockMessageToSlack(boardName, e));
|
||||
|
||||
return publishedMessages.then(Mono.just(APIResponse.success(result.done())));
|
||||
}
|
||||
|
||||
@PostMapping("/exploit/boards/{boardName}")
|
||||
public Mono<APIResponse<String>> crawlBoardDryRun(
|
||||
@PathVariable("boardName") PpomppuBoardName boardName) {
|
||||
log.info("got request... {}", boardName);
|
||||
Mono<String> publishedMessages =
|
||||
ppomppuRSSFeedService.getArticles(boardName)
|
||||
.flatMap(e -> messageSenderService.sendBlockMessageToSlack(boardName, e));
|
||||
|
||||
return publishedMessages.map(APIResponse::success);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@ public class PpomppuArticle extends Auditable {
|
||||
@Column
|
||||
private String articleUrl;
|
||||
|
||||
@Column
|
||||
private String thumbnailUrl;
|
||||
|
||||
@Column
|
||||
private String title;
|
||||
|
||||
@@ -48,11 +51,13 @@ public class PpomppuArticle extends Auditable {
|
||||
|
||||
@Builder
|
||||
public PpomppuArticle(Long id, Long articleId, PpomppuBoardName boardName, String articleUrl,
|
||||
String title, Integer recommended, Integer hit, Instant registeredAt) {
|
||||
String thumbnailUrl, String title, Integer recommended, Integer hit,
|
||||
Instant registeredAt) {
|
||||
this.id = id;
|
||||
this.articleId = articleId;
|
||||
this.boardName = boardName;
|
||||
this.articleUrl = articleUrl;
|
||||
this.thumbnailUrl = thumbnailUrl;
|
||||
this.title = title;
|
||||
this.recommended = recommended;
|
||||
this.hit = hit;
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.processor.dto;
|
||||
|
||||
/**
|
||||
* PpomppuArticle
|
||||
*
|
||||
* @author Shin Woo-jin (woozu.shin@kakaoent.com)
|
||||
* @since 2021-09-08
|
||||
*/
|
||||
public class PpomppuArticleDTO {
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.processor.dto;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.domain.PpomppuArticle;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.util.DateUtil;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* PpomppuArticleParseDTO
|
||||
*
|
||||
* @author Shin Woo-jin (woozu.shin@kakaoent.com)
|
||||
* @since 2021-09-08
|
||||
*/
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
public class PpomppuArticleParseDTO {
|
||||
|
||||
private String id;
|
||||
private String articleId;
|
||||
private String boardName;
|
||||
private String articleUrl;
|
||||
private String thumbnailUrl;
|
||||
private String title;
|
||||
private String hit;
|
||||
private Integer recommended;
|
||||
private String registeredAt;
|
||||
|
||||
@Builder
|
||||
public PpomppuArticleParseDTO(String id, String articleId, String boardName, String articleUrl,
|
||||
String thumbnailUrl, String title, String hit, Integer recommended,
|
||||
String registeredAt) {
|
||||
this.id = id;
|
||||
this.articleId = articleId;
|
||||
this.boardName = boardName;
|
||||
this.articleUrl = articleUrl;
|
||||
this.thumbnailUrl = thumbnailUrl;
|
||||
this.title = title;
|
||||
this.hit = hit;
|
||||
this.recommended = recommended;
|
||||
this.registeredAt = registeredAt;
|
||||
}
|
||||
|
||||
public boolean isInValidated() {
|
||||
return articleId == null || articleId.isEmpty()
|
||||
|| hit == null || hit.isEmpty();
|
||||
}
|
||||
|
||||
public PpomppuArticle convert() {
|
||||
if (isInValidated()) {
|
||||
throw new IllegalArgumentException("PpomppuArticleParseDTO was invalidated");
|
||||
}
|
||||
return PpomppuArticle.builder()
|
||||
.articleId(Long.parseLong(articleId))
|
||||
.title(title)
|
||||
.articleUrl(articleUrl)
|
||||
.thumbnailUrl(thumbnailUrl)
|
||||
.recommended(recommended)
|
||||
.hit(Integer.parseInt(hit))
|
||||
.registeredAt(DateUtil.DATE_TIME_FORMATTER.parse(registeredAt, Instant::from))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.processor.dto;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
@@ -18,41 +14,45 @@ import com.myoa.engineering.crawl.ppomppu.support.dto.code.PpomppuBoardName;
|
||||
*/
|
||||
public final class PpomppuArticleParser {
|
||||
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yy.MM.dd HH:mm:ss")
|
||||
.withZone(ZoneId.of("Asia/Seoul"));
|
||||
|
||||
private PpomppuArticleParser() {}
|
||||
|
||||
public static PpomppuArticle toArticle(Elements articleElement) {
|
||||
final long articleId = PpomppuArticleParser.parseArticleId(articleElement.get(0));
|
||||
final String articleIdString = PpomppuArticleParser.parseArticleId(articleElement.get(0));
|
||||
final String title = PpomppuArticleParser.parseTitle(articleElement.get(2));
|
||||
final String articleUrl = PpomppuArticleParser.parseArticleUrl(articleElement.get(2));
|
||||
final int recommended = PpomppuArticleParser.parseRecommended(articleElement.get(6));
|
||||
final int hit = PpomppuArticleParser.parseHit(articleElement.get(7));
|
||||
final Instant registeredAt = PpomppuArticleParser.parseRegisteredAt(articleElement.get(5));
|
||||
final String thumbnailUrl = PpomppuArticleParser.parseThumbnailUrl(articleElement.get(3));
|
||||
final Integer recommended = PpomppuArticleParser.parseRecommended(articleElement.get(6));
|
||||
final String hitString = PpomppuArticleParser.parseHit(articleElement.get(7));
|
||||
final String registeredAtString = PpomppuArticleParser.parseRegisteredAt(articleElement.get(5));
|
||||
|
||||
return PpomppuArticle.builder()
|
||||
.articleId(articleId)
|
||||
return PpomppuArticleParseDTO.builder()
|
||||
.articleId(articleIdString)
|
||||
.title(title)
|
||||
.articleUrl(articleUrl)
|
||||
.thumbnailUrl(thumbnailUrl)
|
||||
.recommended(recommended)
|
||||
.hit(hit)
|
||||
.registeredAt(registeredAt)
|
||||
.build();
|
||||
.hit(hitString)
|
||||
.registeredAt(registeredAtString)
|
||||
.build()
|
||||
.convert();
|
||||
}
|
||||
|
||||
public static Long parseArticleId(Element td) {
|
||||
return Long.parseLong(td.text().trim());
|
||||
public static String parseArticleId(Element td) {
|
||||
return td.text().trim();
|
||||
}
|
||||
|
||||
public static String parseTitle(Element td) {
|
||||
return td.getElementsByTag("a").text(); // TODO cdn image extracting
|
||||
return td.getElementsByTag("a").text();
|
||||
}
|
||||
|
||||
public static String parseArticleUrl(Element td) {
|
||||
return PpomppuBoardName.ofViewPageUrl(td.getElementsByTag("a").attr("href"));
|
||||
}
|
||||
|
||||
public static String parseThumbnailUrl(Element td) {
|
||||
return "https:" + td.getElementsByTag("img").get(0).attr("src");
|
||||
}
|
||||
|
||||
public static Integer parseRecommended(Element td) {
|
||||
final String voteString = td.text();
|
||||
final int recommended;
|
||||
@@ -67,13 +67,12 @@ public final class PpomppuArticleParser {
|
||||
return recommended;
|
||||
}
|
||||
|
||||
public static Integer parseHit(Element td) {
|
||||
return Integer.parseInt(td.text());
|
||||
public static String parseHit(Element td) {
|
||||
return td.text();
|
||||
}
|
||||
|
||||
public static Instant parseRegisteredAt(Element td) {
|
||||
final String registeredAtString = td.attr("title");
|
||||
return DATE_TIME_FORMATTER.parse(registeredAtString, Instant::from);
|
||||
public static String parseRegisteredAt(Element td) {
|
||||
return td.attr("title");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.processor.dto;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -10,6 +8,8 @@ import java.util.stream.Collectors;
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.domain.PpomppuArticle;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.BlockMessageDTO;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.SimpleMessageDTO;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.code.PpomppuBoardName;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.util.DateUtil;
|
||||
|
||||
/**
|
||||
* PpomppuArticleTransformer
|
||||
@@ -22,16 +22,16 @@ public final class PpomppuArticleTransformer {
|
||||
private PpomppuArticleTransformer() {}
|
||||
|
||||
private static final String MESSAGE_FORMAT_V1 = "%s)) <%s|LINK> `%s` ";
|
||||
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
||||
.withZone(ZoneId.of("Asia/Seoul"));
|
||||
private static final String MESSAGE_FORMAT_V2 = "%s *<%s|LINK>*\n%s";
|
||||
private static final String TITLE_FORMAT_V1 = "_*:hearts: %s | %s*_";
|
||||
|
||||
public static final Function<PpomppuArticle, SimpleMessageDTO> TRANSFORM_TO_MESSAGE_DTO = article ->
|
||||
SimpleMessageDTO.builder()
|
||||
.requestedAt(Instant.now())
|
||||
.publishedAt(article.getRegisteredAt())
|
||||
.title(String.format(MESSAGE_FORMAT_V1,
|
||||
article.getBoardName().getMenuName(), article.getArticleUrl(), article.getTitle()))
|
||||
article.getBoardName().getMenuName(), article.getArticleUrl(),
|
||||
article.getTitle()))
|
||||
.body(article.getArticleUrl())
|
||||
.build();
|
||||
|
||||
@@ -43,25 +43,28 @@ public final class PpomppuArticleTransformer {
|
||||
.collect(Collectors.joining("\n\n"));
|
||||
return SimpleMessageDTO.builder()
|
||||
.requestedAt(requestedAt)
|
||||
.title(DATE_TIME_FORMATTER.format(requestedAt))
|
||||
.title(DateUtil.DATE_TIME_FORMATTER.format(requestedAt))
|
||||
.body(body)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static BlockMessageDTO transformToBlockMessage(List<PpomppuArticle> articles) {
|
||||
public static BlockMessageDTO transformToBlockMessage(PpomppuBoardName boardName, List<PpomppuArticle> articles) {
|
||||
Instant requestedAt = Instant.now();
|
||||
List<String> body = articles.stream()
|
||||
.map(PpomppuArticleTransformer::convertToInlineMessage)
|
||||
List<BlockMessageDTO.Block> body = articles.stream()
|
||||
.map(e -> BlockMessageDTO.createBlock(convertToInlineMessage(e),
|
||||
e.getThumbnailUrl()))
|
||||
.collect(Collectors.toList());
|
||||
return BlockMessageDTO.builder()
|
||||
.requestedAt(requestedAt)
|
||||
.title(DATE_TIME_FORMATTER.format(requestedAt))
|
||||
.title(String.format(TITLE_FORMAT_V1,
|
||||
boardName.getMenuName(),
|
||||
DateUtil.DATE_TIME_FORMATTER.format(requestedAt)))
|
||||
.blocks(body)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static String convertToInlineMessage(PpomppuArticle article) {
|
||||
return String.format(MESSAGE_FORMAT_V1,
|
||||
return String.format(MESSAGE_FORMAT_V2,
|
||||
article.getBoardName().getMenuName(), article.getArticleUrl(), article.getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.springframework.stereotype.Service;
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.domain.PpomppuArticle;
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.dto.PpomppuArticleTransformer;
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.infrastructure.client.MessageSenderAPIClient;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.code.PpomppuBoardName;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -35,8 +36,9 @@ public class MessageSenderService {
|
||||
return messageSenderAPIClient.sendSimpleMessageToSlack(PpomppuArticleTransformer.transformToSimpleMessage(articles));
|
||||
}
|
||||
|
||||
public Mono<String> sendBlockMessageToSlack(List<PpomppuArticle> articles) {
|
||||
return messageSenderAPIClient.sendBlockMessageToSlack(PpomppuArticleTransformer.transformToBlockMessage(articles));
|
||||
public Mono<String> sendBlockMessageToSlack(PpomppuBoardName boardName, List<PpomppuArticle> articles) {
|
||||
return messageSenderAPIClient.sendBlockMessageToSlack(
|
||||
PpomppuArticleTransformer.transformToBlockMessage(boardName, articles));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.processor.service;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.domain.PpomppuArticle;
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.dto.PpomppuArticleParser;
|
||||
import com.myoa.engineering.crawl.ppomppu.processor.infrastructure.client.PpomppuBoardFeedRetriever;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.code.PpomppuBoardName;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -35,6 +37,8 @@ public class PpomppuFeedService {
|
||||
final Mono<Element> tbody = extractTbodyFromHtml(html);
|
||||
// .doOnNext(e -> log.info("pre tbody - {}", e.html()));
|
||||
return extractArticlesFromTbody(tbody).map(this::convertFromElement)
|
||||
.onErrorContinue((t, e) -> log.error("Error occured : {}, value: {}",
|
||||
e, t.getLocalizedMessage()))
|
||||
.map(e -> e.updateBoardName(boardName))
|
||||
.sort(Comparator.comparing(PpomppuArticle::getArticleId))
|
||||
// .doOnNext(e -> log.info("parsed Result: {}", e))
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ParseEventEmitter {
|
||||
this.processorAPIService = processorAPIService;
|
||||
}
|
||||
|
||||
@Scheduled(fixedRate = 300 * 1000L)
|
||||
@Scheduled(fixedRate = 600 * 1000L)
|
||||
public void emitBoards() {
|
||||
log.info("[emitDomesticBoard] trigger fired!");
|
||||
Arrays.stream(PpomppuBoardName.values())
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.myoa.engineering.crawl.ppomppu.sender.dto.SlackBaseMessageBlock;
|
||||
import com.myoa.engineering.crawl.ppomppu.sender.dto.SlackMessageDTO;
|
||||
import com.myoa.engineering.crawl.ppomppu.sender.dto.SlackSectionMessageBlock;
|
||||
import com.myoa.engineering.crawl.ppomppu.sender.infrastructure.client.MongeShoppingBotSlackMessageSender;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.APIResponse;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.BlockMessageDTO;
|
||||
@@ -45,13 +44,19 @@ public class MessageSenderAPIController {
|
||||
if (dto.getBlocks().isEmpty()) {
|
||||
return Mono.just(APIResponse.fail(dto, "empty blocks"));
|
||||
}
|
||||
SlackMessageDTO slackMessageDTO = sender.ofBlockMessageBased();
|
||||
dto.getBlocks().forEach(slackMessageDTO::addBlock);
|
||||
slackMessageDTO.addBlock(SlackBaseMessageBlock.ofDivider());
|
||||
|
||||
return sender.sendMessage(slackMessageDTO)
|
||||
.doOnNext(e -> log.info("[sendBlockMessageToSlack] slackMessageDTO: {}",
|
||||
ObjectMapperFactory.writeAsString(slackMessageDTO)))
|
||||
|
||||
return sender.sendMessage(buildSlackMessageDTO(dto))
|
||||
// .doOnNext(e -> log.info("[sendBlockMessageToSlack] slackMessageDTO: {}",
|
||||
// ObjectMapperFactory.writeAsString(buildSlackMessageDTO(dto))))
|
||||
.then(Mono.just(APIResponse.success(dto)));
|
||||
}
|
||||
|
||||
private SlackMessageDTO buildSlackMessageDTO(BlockMessageDTO dto) {
|
||||
SlackMessageDTO slackMessageDTO = sender.ofBlockMessageBased();
|
||||
slackMessageDTO.addSectionBlock(dto.getTitle());
|
||||
dto.getBlocks().forEach(slackMessageDTO::addSectionBlock);
|
||||
slackMessageDTO.addBlock(SlackBaseMessageBlock.ofDivider());
|
||||
return slackMessageDTO;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public class SlackBaseMessageBlock implements SlackMessageBlock {
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type.getType();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.sender.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* SlackImageMessageBlock
|
||||
* @author Shin Woo-jin (woo-jin.shin@linecorp.com)
|
||||
* @since 2021-11-30
|
||||
*
|
||||
*/
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class SlackImageMessageBlock implements SlackMessageBlock {
|
||||
private static final long serialVersionUID = 1597984001727808419L;
|
||||
|
||||
private SlackMessageBlockType type;
|
||||
|
||||
@JsonProperty(value = "image_url", required = true)
|
||||
private String imageUrl;
|
||||
|
||||
@JsonProperty(value = "alt_text", required = true)
|
||||
private String altText;
|
||||
|
||||
@Builder
|
||||
private SlackImageMessageBlock(SlackMessageBlockType type, String imageUrl, String altText) {
|
||||
this.type = type;
|
||||
this.imageUrl = imageUrl;
|
||||
this.altText = altText;
|
||||
}
|
||||
|
||||
public static SlackImageMessageBlock of(String imageUrl, String altText) {
|
||||
return SlackImageMessageBlock.builder()
|
||||
.type(SlackMessageBlockType.IMAGE)
|
||||
.imageUrl(imageUrl)
|
||||
.altText(altText)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type.getType();
|
||||
}
|
||||
}
|
||||
@@ -9,4 +9,7 @@ import java.io.Serializable;
|
||||
*
|
||||
*/
|
||||
public interface SlackMessageBlock extends Serializable {
|
||||
|
||||
String getType();
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public enum SlackMessageBlockType {
|
||||
SECTION("section"),
|
||||
MARKDOWN("mrkdwn"),
|
||||
DIVIDER("divider"),
|
||||
IMAGE("image"),
|
||||
;
|
||||
|
||||
private String type;
|
||||
|
||||
@@ -4,6 +4,8 @@ import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.BlockMessageDTO;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.BlockMessageDTO.Block;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
@@ -44,8 +46,13 @@ public class SlackMessageDTO implements MessageDTO {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public void addBlock(String blockRawMessage) {
|
||||
addBlock(SlackSectionMessageBlock.ofMarkDown(blockRawMessage));
|
||||
public void addSectionBlock(BlockMessageDTO.Block block) {
|
||||
SlackSectionMessageBlock slackSectionMessageBlock = SlackSectionMessageBlock.ofMarkDown(block.getText());
|
||||
slackSectionMessageBlock.applyImageaccessory(block.getImageUrl(), block.getAltText());
|
||||
addBlock(slackSectionMessageBlock);
|
||||
}
|
||||
public void addSectionBlock(String rawBlockMessage) {
|
||||
addBlock(SlackSectionMessageBlock.ofMarkDown(rawBlockMessage));
|
||||
}
|
||||
|
||||
public void addBlock(SlackMessageBlock block) {
|
||||
|
||||
@@ -20,11 +20,14 @@ public class SlackSectionMessageBlock implements SlackMessageBlock {
|
||||
|
||||
private SlackMessageBlockType type;
|
||||
private SlackBaseMessageBlock text;
|
||||
private SlackImageMessageBlock accessory;
|
||||
|
||||
@Builder
|
||||
private SlackSectionMessageBlock(SlackMessageBlockType type, SlackBaseMessageBlock text) {
|
||||
private SlackSectionMessageBlock(SlackMessageBlockType type, SlackBaseMessageBlock text,
|
||||
SlackImageMessageBlock accessory) {
|
||||
this.type = type;
|
||||
this.text = text;
|
||||
this.accessory = accessory;
|
||||
}
|
||||
|
||||
public static SlackSectionMessageBlock ofMarkDown(String message) {
|
||||
@@ -34,6 +37,12 @@ public class SlackSectionMessageBlock implements SlackMessageBlock {
|
||||
.build();
|
||||
}
|
||||
|
||||
public SlackSectionMessageBlock applyImageaccessory(String imageUrl, String altText) {
|
||||
this.accessory = SlackImageMessageBlock.of(imageUrl, altText);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type.getType();
|
||||
}
|
||||
|
||||
@@ -1,38 +1,68 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.support.dto;
|
||||
package com.myoa.engineering.crawl.ppomppu.support.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.code.PpomppuBoardName;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
/**
|
||||
* SimpleMessageDTO
|
||||
* @author Shin Woo-jin (woo-jin.shin@linecorp.com)
|
||||
* @since 2021-11-21
|
||||
*
|
||||
*/
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
public class BlockMessageDTO implements Serializable {
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
public class BlockMessageDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6992039884035135523L;
|
||||
|
||||
private PpomppuBoardName boardName;
|
||||
private String title;
|
||||
private List<String> blocks;
|
||||
private List<Block> blocks;
|
||||
private String url;
|
||||
private Instant publishedAt;
|
||||
private Instant requestedAt;
|
||||
|
||||
@Builder
|
||||
public BlockMessageDTO(String title, List<String> blocks, String url, Instant publishedAt,
|
||||
public BlockMessageDTO(PpomppuBoardName boardName, String title,
|
||||
List<Block> blocks, String url, Instant publishedAt,
|
||||
Instant requestedAt) {
|
||||
this.boardName = boardName;
|
||||
this.title = title;
|
||||
this.blocks = blocks;
|
||||
this.url = url;
|
||||
this.publishedAt = publishedAt;
|
||||
this.requestedAt = requestedAt;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
public static class Block implements Serializable {
|
||||
private static final long serialVersionUID = 3633781631892663709L;
|
||||
|
||||
private String text;
|
||||
private String imageUrl;
|
||||
private String altText;
|
||||
|
||||
public Block(String text, String imageUrl, String altText) {
|
||||
this.text = text;
|
||||
this.imageUrl = imageUrl;
|
||||
this.altText = altText;
|
||||
}
|
||||
}
|
||||
|
||||
public static Block createBlock(String text, String imageUrl) {
|
||||
return new Block(text, imageUrl, "");
|
||||
}
|
||||
|
||||
public static Block createBlock(String text, String imageUrl, String altText) {
|
||||
return new Block(text, imageUrl, altText);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,30 +12,30 @@ import lombok.Getter;
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum PpomppuBoardName {
|
||||
PPOMPPU_DOMESTIC_ALL("/zboard/zboard.php?id=ppomppu", "국내-전체", true),
|
||||
PPOMPPU_DOMESTIC_ETC("/zboard/zboard.php?id=ppomppu&category=1", "국내-기타", false),
|
||||
PPOMPPU_DOMESTIC_COMPUTER("/zboard/zboard.php?id=ppomppu&category=4", "국내-컴퓨터", false),
|
||||
PPOMPPU_DOMESTIC_DIGITAL("/zboard/zboard.php?id=ppomppu&category=5", "국내-디지털", false),
|
||||
PPOMPPU_DOMESTIC_FOOD("/zboard/zboard.php?id=ppomppu&category=6", "국내-식품/건강", false),
|
||||
PPOMPPU_DOMESTIC_BOOK("/zboard/zboard.php?id=ppomppu&category=8", "국내-서적", false),
|
||||
PPOMPPU_DOMESTIC_APPLIANCES("/zboard/zboard.php?id=ppomppu&category=9", "국내-가전/가구", false),
|
||||
PPOMPPU_DOMESTIC_PARENTING("/zboard/zboard.php?id=ppomppu&category=10", "국내-육아", false),
|
||||
PPOMPPU_DOMESTIC_GIFTCARD("/zboard/zboard.php?id=ppomppu&category=11", "국내-상품권", false),
|
||||
PPOMPPU_DOMESTIC_CLOTHES("/zboard/zboard.php?id=ppomppu&category=12", "국내-의류/잡화", false),
|
||||
PPOMPPU_DOMESTIC_COSMETIC("/zboard/zboard.php?id=ppomppu&category=13", "국내-화장품", false),
|
||||
PPOMPPU_DOMESTIC_OUTDOOR("/zboard/zboard.php?id=ppomppu&category=15", "국내-등산/캠핑", false),
|
||||
PPOMPPU_OVERSEA_ALL("/zboard/zboard.php?id=ppomppu4", "해외-전체", true),
|
||||
PPOMPPU_OVERSEA_ETC("/zboard/zboard.php?id=ppomppu4&category=1", "해외-기타", false),
|
||||
PPOMPPU_OVERSEA_APPLIANCES("/zboard/zboard.php?id=ppomppu4&category=7", "해외-가전", false),
|
||||
PPOMPPU_OVERSEA_TVAV("/zboard/zboard.php?id=ppomppu4&category=8", "해외-TV/영상", false),
|
||||
PPOMPPU_OVERSEA_COMPUTER("/zboard/zboard.php?id=ppomppu4&category=3", "해외-컴퓨터", false),
|
||||
PPOMPPU_OVERSEA_DIGITAL("/zboard/zboard.php?id=ppomppu4&category=4", "해외-디지털", false),
|
||||
PPOMPPU_OVERSEA_MOBILEACCESSORY("/zboard/zboard.php?id=ppomppu4&category=9", "해외-액세서리", false),
|
||||
PPOMPPU_OVERSEA_CLOTHES("/zboard/zboard.php?id=ppomppu4&category=5", "해외-의류/잡화", false),
|
||||
PPOMPPU_OVERSEA_WATCH("/zboard/zboard.php?id=ppomppu4&category=2", "해외-시계", false),
|
||||
PPOMPPU_OVERSEA_SHOES("/zboard/zboard.php?id=ppomppu4&category=11", "해외-신발", false),
|
||||
PPOMPPU_OVERSEA_FOOD("/zboard/zboard.php?id=ppomppu4&category=10", "해외-식품/건강", false),
|
||||
PPOMPPU_OVERSEA_PARENTING("/zboard/zboard.php?id=ppomppu4&category=6", "해외-육아", false),
|
||||
PPOMPPU_DOMESTIC_ALL("/zboard/zboard.php?id=ppomppu", "국내-전체", false),
|
||||
PPOMPPU_DOMESTIC_ETC("/zboard/zboard.php?id=ppomppu&category=1", "국내-기타", true),
|
||||
PPOMPPU_DOMESTIC_COMPUTER("/zboard/zboard.php?id=ppomppu&category=4", "국내-컴퓨터", true),
|
||||
PPOMPPU_DOMESTIC_DIGITAL("/zboard/zboard.php?id=ppomppu&category=5", "국내-디지털", true),
|
||||
PPOMPPU_DOMESTIC_FOOD("/zboard/zboard.php?id=ppomppu&category=6", "국내-식품/건강", true),
|
||||
PPOMPPU_DOMESTIC_BOOK("/zboard/zboard.php?id=ppomppu&category=8", "국내-서적", true),
|
||||
PPOMPPU_DOMESTIC_APPLIANCES("/zboard/zboard.php?id=ppomppu&category=9", "국내-가전/가구", true),
|
||||
PPOMPPU_DOMESTIC_PARENTING("/zboard/zboard.php?id=ppomppu&category=10", "국내-육아", true),
|
||||
PPOMPPU_DOMESTIC_GIFTCARD("/zboard/zboard.php?id=ppomppu&category=11", "국내-상품권", true),
|
||||
PPOMPPU_DOMESTIC_CLOTHES("/zboard/zboard.php?id=ppomppu&category=12", "국내-의류/잡화", true),
|
||||
PPOMPPU_DOMESTIC_COSMETIC("/zboard/zboard.php?id=ppomppu&category=13", "국내-화장품", true),
|
||||
PPOMPPU_DOMESTIC_OUTDOOR("/zboard/zboard.php?id=ppomppu&category=15", "국내-등산/캠핑", true),
|
||||
PPOMPPU_OVERSEA_ALL("/zboard/zboard.php?id=ppomppu4", "해외-전체", false),
|
||||
PPOMPPU_OVERSEA_ETC("/zboard/zboard.php?id=ppomppu4&category=1", "해외-기타", true),
|
||||
PPOMPPU_OVERSEA_APPLIANCES("/zboard/zboard.php?id=ppomppu4&category=7", "해외-가전", true),
|
||||
PPOMPPU_OVERSEA_TVAV("/zboard/zboard.php?id=ppomppu4&category=8", "해외-TV/영상", true),
|
||||
PPOMPPU_OVERSEA_COMPUTER("/zboard/zboard.php?id=ppomppu4&category=3", "해외-컴퓨터", true),
|
||||
PPOMPPU_OVERSEA_DIGITAL("/zboard/zboard.php?id=ppomppu4&category=4", "해외-디지털", true),
|
||||
PPOMPPU_OVERSEA_MOBILEACCESSORY("/zboard/zboard.php?id=ppomppu4&category=9", "해외-액세서리", true),
|
||||
PPOMPPU_OVERSEA_CLOTHES("/zboard/zboard.php?id=ppomppu4&category=5", "해외-의류/잡화", true),
|
||||
PPOMPPU_OVERSEA_WATCH("/zboard/zboard.php?id=ppomppu4&category=2", "해외-시계", true),
|
||||
PPOMPPU_OVERSEA_SHOES("/zboard/zboard.php?id=ppomppu4&category=11", "해외-신발", true),
|
||||
PPOMPPU_OVERSEA_FOOD("/zboard/zboard.php?id=ppomppu4&category=10", "해외-식품/건강", true),
|
||||
PPOMPPU_OVERSEA_PARENTING("/zboard/zboard.php?id=ppomppu4&category=6", "해외-육아", true),
|
||||
;
|
||||
|
||||
private String resourcePath;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.support.util;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* DateUtil
|
||||
* @author Shin Woo-jin (woo-jin.shin@linecorp.com)
|
||||
* @since 2022-01-02
|
||||
*
|
||||
*/
|
||||
public final class DateUtil {
|
||||
|
||||
private DateUtil() { }
|
||||
|
||||
public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yy.MM.dd HH:mm:ss")
|
||||
.withZone(ZoneId.of("Asia/Seoul"));
|
||||
}
|
||||
Reference in New Issue
Block a user