Skip to content

Instantly share code, notes, and snippets.

@wheeliechamp
Created October 20, 2021 15:25
Show Gist options
  • Save wheeliechamp/5efc1d5ee2b3be3619a235cdbfcd1bdd to your computer and use it in GitHub Desktop.
Save wheeliechamp/5efc1d5ee2b3be3619a235cdbfcd1bdd to your computer and use it in GitHub Desktop.
Slack投稿用メソッド追加
package com.example.webscrapingtest.viewmodel
import android.util.Log
import androidx.lifecycle.ViewModel
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.jsoup.select.Elements
import com.github.kittinunf.fuel.Fuel
class MainViewModel : ViewModel() {
// TODO: Implement the ViewModel
fun analyzeHtml(src: String) {
var document: Document = Jsoup.parse(src)
var elements: Elements = document.getElementsByClass("LifeToolLocalWeatherItem__body")
sendMessage(elements.text())
}
// Slackにメッセージ送信
fun sendMessage(msg: String) {
val webhook: String = "Slack Webhook で生成したURL"
val body: String = "{ \"text\" : \"$msg\" }"
Fuel.post(webhook).body(body).response { _, response, result ->
Log.d("Send", response.toString())
Log.d("Send", result.toString())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment