Created
October 20, 2021 15:25
-
-
Save wheeliechamp/5efc1d5ee2b3be3619a235cdbfcd1bdd to your computer and use it in GitHub Desktop.
Slack投稿用メソッド追加
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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