Skip to content

Commit

Permalink
Fixes for search function. some compatibility changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
EATSTEAK committed Jun 1, 2019
1 parent 3f30006 commit c99a40b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'me.itstake.neisinfo'
version '1.1-SNAPSHOT'
version '1.1.1-SNAPSHOT'

repositories {
mavenCentral()
Expand Down
16 changes: 11 additions & 5 deletions src/main/kotlin/me/itstake/neisinfo/School.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.itstake.neisinfo

import org.json.JSONArray
import org.json.JSONObject
import java.net.URL
import java.net.URLEncoder
Expand Down Expand Up @@ -68,11 +67,18 @@ class School(val type:SchoolType, val region:SchoolRegion, val code:String) {
*/
fun findSchool(region: SchoolRegion, name: String):ArrayList<School> {
val data = URL("https://par.${region.url}/spr_ccm_cm01_100.do?kraOrgNm=${URLEncoder.encode(name, "utf-8")}&").readText(Charsets.UTF_8)
val results = (JSONObject(data).get("resultSVO") as JSONObject).get("orgDVOList") as JSONArray
val results = JSONObject(data).getJSONObject("resultSVO").getJSONObject("data").getJSONArray("orgDVOList")
val resultMap = ArrayList<School>()
results.forEach { u ->
val si = u as JSONObject
resultMap.add(School(SchoolType.getByType(si["schulCrseScCode"].toString().toInt()), region, si["orgCode"] as String))
for (i in 0 until results.length()) {
val si = results.getJSONObject(i)
resultMap.add(
School(
SchoolType.getByType(si["schulCrseScCode"].toString().toInt()),
region,
si["orgCode"] as String,
si["kraOrgNm"] as String
)
)
}
return resultMap
}
Expand Down

0 comments on commit c99a40b

Please # to comment.