2024-09-25 16:50:58 +09:00
|
|
|
package kr.lunaticbum.back.lun
|
|
|
|
|
|
2024-09-25 18:24:47 +09:00
|
|
|
import com.google.gson.Gson
|
|
|
|
|
import kr.lunaticbum.back.lun.model.CurrentWeather
|
2024-09-25 16:50:58 +09:00
|
|
|
import org.springframework.boot.CommandLineRunner
|
|
|
|
|
import org.springframework.boot.SpringApplication
|
|
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication
|
|
|
|
|
import org.springframework.boot.runApplication
|
|
|
|
|
import org.springframework.context.annotation.Bean
|
2024-09-25 18:24:47 +09:00
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled
|
|
|
|
|
import org.springframework.web.reactive.function.client.WebClient
|
|
|
|
|
import java.time.LocalDateTime
|
2024-09-25 16:50:58 +09:00
|
|
|
import java.util.*
|
|
|
|
|
|
2024-09-25 18:24:47 +09:00
|
|
|
@EnableScheduling // 추가
|
2024-09-25 16:50:58 +09:00
|
|
|
@SpringBootApplication
|
2024-09-25 18:24:47 +09:00
|
|
|
class LunApplication {
|
|
|
|
|
@Scheduled(cron = "0 0 0/4 * * *") //
|
|
|
|
|
fun runJob() {
|
|
|
|
|
try {
|
|
|
|
|
val client0 = WebClient.create()
|
|
|
|
|
val result = client0.get()
|
|
|
|
|
.uri("http://api.weatherapi.com/v1/current.json?key=de574a260b1f474d99955729241909&q=seoul&aqi=no")
|
|
|
|
|
.retrieve()
|
|
|
|
|
.bodyToMono(String::class.java).block() ?: "FAIL"
|
|
|
|
|
var sss = Gson().fromJson<CurrentWeather>(result,CurrentWeather::class.java)
|
|
|
|
|
|
|
|
|
|
val client = WebClient.create()
|
|
|
|
|
client.get()
|
|
|
|
|
.uri("https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/sendMessage?chat_id=71476436&text=온도${sss.current?.temp_c}")
|
|
|
|
|
.retrieve()
|
|
|
|
|
.bodyToMono(String::class.java).block() ?: "FAIL"
|
|
|
|
|
}catch (e : Exception) {
|
|
|
|
|
e.printStackTrace()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-25 16:50:58 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
fun main(args: Array<String>) {
|
|
|
|
|
runApplication<LunApplication>(*args)
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
//@SpringBootApplication
|
|
|
|
|
//class Application {
|
|
|
|
|
// @Bean
|
|
|
|
|
// fun commandLineRunner(ctx: ApplicationContext): CommandLineRunner {
|
|
|
|
|
// return CommandLineRunner { args: Array<String?>? ->
|
|
|
|
|
// println("Let's inspect the beans provided by Spring Boot:")
|
|
|
|
|
// val beanNames: Array<String> = ctx.getBeanDefinitionNames()
|
|
|
|
|
// Arrays.sort(beanNames)
|
|
|
|
|
// for (beanName in beanNames) {
|
|
|
|
|
// println(beanName)
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// companion object {
|
|
|
|
|
// @JvmStatic
|
|
|
|
|
// fun main(args: Array<String>) {
|
|
|
|
|
// SpringApplication.run(Application::class.java, *args)
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//}
|