Created
March 21, 2019 11:23
-
-
Save antonis/4af8b14a36f173b4e8e1390dbb191e99 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import com.google.gson.* | |
| fun wikipedia(keyword: String): String { | |
| val url = "https://en.wikipedia.org/w/api.php" + | |
| "?action=query&format=json&prop=extracts" + | |
| "&exsectionformat=plain&exsentences=2&explaintext=1" + | |
| "&titles=$keyword" | |
| val json = java.net.URL(url).readText() | |
| val jsonObject = Gson().fromJson<JsonObject>(json, JsonObject::class.java) | |
| val pages = jsonObject["query"].asJsonObject["pages"].asJsonObject | |
| val extract = pages[pages.keySet().first()].asJsonObject["extract"] | |
| return extract.asString | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment