1
0

feat: 增加新站点采集

This commit is contained in:
2024-11-05 15:14:13 +08:00
parent de585e3016
commit bd67c9f830
3 changed files with 50 additions and 33 deletions

View File

@@ -56,9 +56,18 @@ class Application : ApplicationRunner, ApplicationListener<ContextClosedEvent> {
@Resource
private lateinit var pushRunner: PushRunner
@Resource
private lateinit var articleRepository: ArticleRepository
override fun run(args: ApplicationArguments?) {
// pushRunner.run()
// newsRunner.run()
sites
.filterNot { articleRepository.existsByCode(it.code) }
.forEach {
logger.info("发现新站点:{}", it.name)
newsRunner.run(it.code)
}
}
override fun onApplicationEvent(event: ContextClosedEvent) {

View File

@@ -34,6 +34,8 @@ interface ArticleRepository : JpaRepository<Article, String>, JpaSpecificationEx
fun findAllByDescriptionIsNullAndTextIsNotNull(): List<Article>
fun findAllByHtmlIsNotNull(): List<Article>
fun existsByCode(code: String): Boolean
@Modifying
@Transactional
@Query("update Article article set article.pushed = :pushed where article.id = :id")

View File

@@ -45,7 +45,13 @@ class NewsRunner : Runner {
@Scheduled(cron = "0 0 6-18 * * ?")
override fun run() {
sites.forEach { site ->
sites.forEach { run(it.code) }
}
fun run(code: String) {
sites
.filter { it.code == code }
.forEach { site ->
logger.info("站点: {}", site.name)
keywords.forEach { keyword ->
val url = site.search.replace("{query}", keyword)