feat: 增加新站点采集
This commit is contained in:
@@ -56,9 +56,18 @@ class Application : ApplicationRunner, ApplicationListener<ContextClosedEvent> {
|
|||||||
@Resource
|
@Resource
|
||||||
private lateinit var pushRunner: PushRunner
|
private lateinit var pushRunner: PushRunner
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private lateinit var articleRepository: ArticleRepository
|
||||||
|
|
||||||
override fun run(args: ApplicationArguments?) {
|
override fun run(args: ApplicationArguments?) {
|
||||||
// pushRunner.run()
|
// pushRunner.run()
|
||||||
// newsRunner.run()
|
// newsRunner.run()
|
||||||
|
sites
|
||||||
|
.filterNot { articleRepository.existsByCode(it.code) }
|
||||||
|
.forEach {
|
||||||
|
logger.info("发现新站点:{}", it.name)
|
||||||
|
newsRunner.run(it.code)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onApplicationEvent(event: ContextClosedEvent) {
|
override fun onApplicationEvent(event: ContextClosedEvent) {
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ interface ArticleRepository : JpaRepository<Article, String>, JpaSpecificationEx
|
|||||||
fun findAllByDescriptionIsNullAndTextIsNotNull(): List<Article>
|
fun findAllByDescriptionIsNullAndTextIsNotNull(): List<Article>
|
||||||
fun findAllByHtmlIsNotNull(): List<Article>
|
fun findAllByHtmlIsNotNull(): List<Article>
|
||||||
|
|
||||||
|
fun existsByCode(code: String): Boolean
|
||||||
|
|
||||||
@Modifying
|
@Modifying
|
||||||
@Transactional
|
@Transactional
|
||||||
@Query("update Article article set article.pushed = :pushed where article.id = :id")
|
@Query("update Article article set article.pushed = :pushed where article.id = :id")
|
||||||
|
|||||||
@@ -45,7 +45,13 @@ class NewsRunner : Runner {
|
|||||||
|
|
||||||
@Scheduled(cron = "0 0 6-18 * * ?")
|
@Scheduled(cron = "0 0 6-18 * * ?")
|
||||||
override fun run() {
|
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)
|
logger.info("站点: {}", site.name)
|
||||||
keywords.forEach { keyword ->
|
keywords.forEach { keyword ->
|
||||||
val url = site.search.replace("{query}", keyword)
|
val url = site.search.replace("{query}", keyword)
|
||||||
|
|||||||
Reference in New Issue
Block a user