-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.ts
More file actions
53 lines (44 loc) · 2.17 KB
/
Copy pathmod.ts
File metadata and controls
53 lines (44 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Nominal, tuple } from "https://raw.githubusercontent.com/randkid/Randkid/master/mod.ts"
import residence from "https://raw.githubusercontent.com/randkid/residence/master/mod.ts"
import birthdate from "https://raw.githubusercontent.com/randkid/birthdate/master/mod.ts"
import cheerio from "https://dev.jspm.io/cheerio"
import proj4 from "https://dev.jspm.io/proj4"
const form = (data: Record<string, string>) => {
let result = new URLSearchParams
for (const key in data) {
result.append(key, data[key])
}
return result
}
export default new Nominal({
categories: [],
inputMaterials: tuple([residence, birthdate]),
async rand(seed, residenceVal, birthdateVal) {
const age = (new Date).getFullYear() - (new Date(birthdateVal)).getFullYear() + 1
const schoolType = age > 16 ? 3 : age > 13 ? 2 : 1
const data = await fetch("https://schoolzone.emac.kr/gis/totalSearch.do", {
method: "POST",
body: form({searchText: residenceVal[1]})
}).then(x => x.text())
const $ = cheerio.load(data)
const [match, lon, lat] = $("div.result_content_sec:nth-child(3) > div:nth-child(3) > ul:nth-child(3) > li:nth-child(1) > input:nth-child(1)").attr("onclick").match(/parent\.fn_getSchoolArea\((.+),(.+),'.+','vworld'\);/)
const epsg5186 = "+proj=tmerc +lat_0=38 +lon_0=127 +k=1 +x_0=200000 +y_0=600000 +ellps=GRS80 +units=m +no_defs "
const [x, y] = proj4("EPSG:4326", epsg5186, [Number(lon), Number(lat)])
const schoolArea = await fetch("https://schoolzone.emac.kr/gis/schoolAreaSearch.do", {
method: "POST",
body: form({
x, y, lon, lat,
schoolType: "elementSchoolArea"
})
}).then(x => x.text())
const $2 = cheerio.load(schoolArea)
const schools = Array.from($2("tr")).map(
({attribs}: any) => {
if (attribs.schoolname && attribs.schooltype == schoolType) {
return [attribs.schoolname, attribs.eduarea, attribs.schooltype]
}
}
).filter(x => x)
return schools[Math.floor(Math.random() * schools.length)]
}
})