package kr.lunaticbum.back.lun import com.google.gson.Gson import kr.lunaticbum.back.lun.model.CurrentWeather 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 import org.springframework.scheduling.annotation.EnableScheduling import org.springframework.scheduling.annotation.Scheduled import org.springframework.web.reactive.function.client.WebClient import java.time.LocalDateTime import java.util.* @EnableScheduling // 추가 @SpringBootApplication 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(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() } } } fun main(args: Array) { runApplication(*args) } // //@SpringBootApplication //class Application { // @Bean // fun commandLineRunner(ctx: ApplicationContext): CommandLineRunner { // return CommandLineRunner { args: Array? -> // println("Let's inspect the beans provided by Spring Boot:") // val beanNames: Array = ctx.getBeanDefinitionNames() // Arrays.sort(beanNames) // for (beanName in beanNames) { // println(beanName) // } // } // } // // companion object { // @JvmStatic // fun main(args: Array) { // SpringApplication.run(Application::class.java, *args) // } // } //}