This commit is contained in:
lunaticbum 2024-10-17 18:07:49 +09:00
parent 8e64f444a5
commit 7bfd2a0e62
6 changed files with 118 additions and 32 deletions

View File

@ -11,11 +11,13 @@ import org.springframework.web.reactive.function.client.WebClient
@SpringBootApplication
class LunApplication {
init {
val client = WebClient.create()
client.get()
.uri("https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/sendMessage?chat_id=71476436&text=SERVER_START")
.retrieve()
.bodyToMono(String::class.java).block() ?: "FAIL"
try {
val client = WebClient.create()
client.get()
.uri("https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/sendMessage?chat_id=71476436&text=SERVER_START")
.retrieve()
.bodyToMono(String::class.java).block() ?: "FAIL"
} catch (e : Exception) {}
}

View File

@ -1,8 +1,12 @@
package kr.lunaticbum.back.lun.controllers
import com.google.gson.Gson
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import kr.lunaticbum.back.lun.configs.GlobalEnvironment
import kr.lunaticbum.back.lun.model.CurrentWeather
import kr.lunaticbum.back.lun.model.FileSaveResult
import kr.lunaticbum.back.lun.model.LocationLogService
import kr.lunaticbum.back.lun.model.ResponceResult
import kr.lunaticbum.back.lun.utils.LogService
import kr.lunaticbum.back.lun.utils.getFileExtension
@ -14,6 +18,7 @@ import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile
import org.springframework.web.reactive.function.client.WebClient
import org.springframework.web.servlet.ModelAndView
import java.io.*
import java.util.*
@ -23,6 +28,12 @@ import java.util.*
@RequestMapping("/blog")
class BlogController() {
@Autowired
lateinit var globalEvv : GlobalEnvironment
@Autowired
private lateinit var locationLogService: LocationLogService
@Autowired
lateinit var logService: LogService
@ -52,6 +63,32 @@ class BlogController() {
return vm
}
@GetMapping("recent")
fun recent() : ModelAndView{
val vm = ModelAndView("content/blog/viewer")
locationLogService.find50().forEach {
logService.log(Gson().toJson(it))
}
locationLogService.getLocationLog()?.let {
try {
val client0 = WebClient.create()
val result = client0.get()
.uri("http://api.weatherapi.com/v1/current.json?key=${globalEvv.weatherApiKey}&q=${it.mLatitude},${it.mLongitude}&aqi=no")
.retrieve()
.bodyToMono(String::class.java)
.block() ?: "FAIL"
Gson().fromJson(result, CurrentWeather::class.java)?.let { sss ->
logService.log("지역:${sss.location?.name}\n날씨:${sss.current?.condition?.text}\n온도:${sss.current?.temp_c}\n습도:${sss.current?.humidity}\n" +
"체감온도:${sss.current?.feelslike_c}\nhttps://www.accuweather.com/ko/search-locations?query=${it.mLatitude},${it.mLongitude}")
}
}
catch (e : Exception) {
}
}
return vm
}
@Value("\${image.upload.path}")
private val uploadPath: String? = null

View File

@ -2,6 +2,9 @@ package kr.lunaticbum.back.lun.controllers
import com.google.gson.Gson
import jakarta.servlet.http.HttpServletRequest
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kr.lunaticbum.back.lun.configs.GlobalEnvironment
import kr.lunaticbum.back.lun.model.*
import kr.lunaticbum.back.lun.utils.LogService
@ -10,6 +13,7 @@ import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.web.bind.annotation.*
import org.springframework.web.reactive.function.client.WebClient
import java.util.*
@ -32,9 +36,11 @@ class BumsPrivate {
logService.log(jsonString)
var lResultCode = 0
var lResultMsg = "Suscces"
var location : LocationLog? = null
val decodedBytes: ByteArray = Base64.getMimeDecoder().decode(jsonString)
String(decodedBytes).let {
Gson().fromJson<LocationLog>(it, LocationLog::class.java)?.let { model ->
location = model
logService.log(model.toString())
locationService.save(model)
}
@ -43,6 +49,15 @@ class BumsPrivate {
this.resultCode = lResultCode
this.resultMsg = lResultMsg
})
CoroutineScope(Dispatchers.IO).launch {
location?.let {
val client = WebClient.create()
client.get()
.uri("https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=${it.mAddressLines.first()} 저장")
.retrieve()
.bodyToMono(String::class.java).block() ?: "FAIL"
}
}
return responce
}

View File

@ -128,18 +128,25 @@ class Telegram {
((globalEvv.telegramBotKey?.length ?: 0) > 3) &&
((globalEvv.telegramMyId?.length ?: 0) > 3)
) {
val client0 = WebClient.create()
val result = client0.get()
.uri("http://api.weatherapi.com/v1/current.json?key=${globalEvv.weatherApiKey}&q=seoul&aqi=no")
.retrieve()
.bodyToMono(String::class.java)
.block() ?: "FAIL"
Gson().fromJson(result, CurrentWeather::class.java)?.let { sss ->
val client = WebClient.create()
client.get()
.uri("https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=온도${sss.current?.temp_c}")
.retrieve()
.bodyToMono(String::class.java).block() ?: "FAIL"
locationLogService.getLocationLog()?.let {
try {
val client0 = WebClient.create()
val result = client0.get()
.uri("http://api.weatherapi.com/v1/current.json?key=${globalEvv.weatherApiKey}&q=${it.mLatitude},${it.mLongitude}&aqi=no")
.retrieve()
.bodyToMono(String::class.java)
.block() ?: "FAIL"
Gson().fromJson(result, CurrentWeather::class.java)?.let { sss ->
val client = WebClient.create()
client.get()
.uri("https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=${sss.getSummaryInfo()}")
.retrieve()
.bodyToMono(String::class.java).block() ?: "FAIL"
}
}
catch (e : Exception) {
}
}
}
}catch (e : Exception) {
@ -217,7 +224,7 @@ class Telegram {
val client = WebClient.create()
locationLogService.getLocationLog()?.let {
client.get()
.uri("https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${target}&text=${SimpleDateFormat("yyyy/MM/dd-HH:mm:ss").format(Date(it.time))}\n${it.mAddressLines.first()}")
.uri("https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${target}&text=${it.timeString}\n${it.mAddressLines.first()}\nhttps://www.google.com/maps/search/?api=1&query=${it.mLatitude},${it.mLongitude}")
.retrieve()
.bodyToMono(String::class.java).block() ?: "FAIL"
}

View File

@ -1,6 +1,10 @@
package kr.lunaticbum.back.lun.model
import com.google.gson.Gson
import com.mongodb.client.model.Sorts.descending
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kr.lunaticbum.back.lun.configs.GlobalEnvironment
import kr.lunaticbum.back.lun.utils.LogService
import lombok.AllArgsConstructor
@ -16,8 +20,10 @@ import org.springframework.data.mongodb.repository.ReactiveMongoRepository
import org.springframework.stereotype.Repository
import org.springframework.stereotype.Service
import org.springframework.web.reactive.function.client.WebClient
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import java.text.SimpleDateFormat
import java.time.Duration
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.List
@ -47,6 +53,7 @@ class LocationLog {
var mHasLatitude = false
var mHasLongitude = false
var mPhone: String? = null
var timeString : String? = null
var mUrl: String? = null
var time : Long = 0L
@ -75,6 +82,7 @@ class LocationLog {
@Repository
interface LocationLogRepository : ReactiveMongoRepository<LocationLog, String> {
fun findAllBy() : Mono<LocationLog>
fun findFirstByOrderByTimeDesc() : Mono<LocationLog>
fun save(log: LocationLog): Mono<LocationLog>
}
@ -90,6 +98,9 @@ class LocationLogService : LocationService {
@Autowired
private lateinit var logRepository: LocationLogRepository
fun find50() : List<LocationLog> {
return logRepository.findAll().takeLast(50).buffer(50).blockLast(Duration.ofSeconds(30)) ?: listOf()
}
fun getLocationLog() : LocationLog? {
return logRepository.findFirstByOrderByTimeDesc().block()
}
@ -258,11 +269,16 @@ object QVZTb2dpcmw : SoInterface {
this.thumbnail = img
this.pubDate = Date().time
this.category = RssDataType.GURU.name
})
}) {
// CoroutineScope(Dispatchers.IO).launch {
// service.sendMsg("${title}\n${img}\n${href}")
// }
}
}
service.sendMsg(lists.map {
"${it.title}\n${it.description}\n${it.thumbnail}\n${it.originPage}\n"
}.joinToString(" \n "))
// lists.map {
// service.sendMsg("${it.title}\n${it.description}\n${it.thumbnail}\n${it.originPage}")
// }
}
}
@ -291,12 +307,16 @@ object SkFWTW9zdA : SoInterface {
try {
pubDate = dmy.parse(date).time
}catch (e : Exception) {e.printStackTrace()}
})
}){
// CoroutineScope(Dispatchers.IO).launch {
// service.sendMsg("${title}\n${thumb}\n${link}")
// }
}
}
}
service.sendMsg(lists.map {
"${it.title}\n${it.description}\n${it.thumbnail}\n${it.originPage}\n"
}.joinToString(" \n "))
// service.sendMsg(lists.map {
// "${it.title}\n${it.description}\n${it.thumbnail}\n${it.originPage}\n"
// }.joinToString(" \n "))
}
}
@Repository
@ -321,27 +341,29 @@ class RssDataService {
}
fun save(log: RssData) {
fun save(log: RssData, callback : (Boolean)->Unit) {
println("saved msg before ${Gson().toJson(log)}")
log.originPage?.let {
if(rssDataRepository.findFirstByOriginPageEquals(it).block() == null) {
rssDataRepository.save(log)
.subscribe({ println("saved msg after ${it}") }, { e -> e.printStackTrace() }, {
println("saved msg comp")
callback(true)
})
} else {
println("있어???")
}
}
}
@Autowired
lateinit var globalEvv : GlobalEnvironment
fun sendMsg(data : String) {
suspend fun sendMsg(data : String) {
val client = WebClient.create()
client.get()
.uri("https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=${data}")
.retrieve()
.bodyToMono(String::class.java).block() ?: "FAIL"
client.get()
.uri("https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=${data}")
.retrieve()
.bodyToMono(String::class.java).block() ?: "FAIL"
}
}

View File

@ -52,4 +52,7 @@ class Location {
class CurrentWeather {
var location: Location? = null
var current: Current? = null
fun getSummaryInfo() = "지역:${this.location?.name}\n날씨:${this.current?.condition?.text}\n온도:${this.current?.temp_c}\n습도:${this.current?.humidity}\n" +
"체감온도:${this.current?.feelslike_c}\nhttps://www.accuweather.com/ko/search-locations?query=${this.location?.lat},${this.location?.lon}"
}