Skip to content

Instantly share code, notes, and snippets.

@mu-hun
Last active October 20, 2019 11:50
Show Gist options
  • Select an option

  • Save mu-hun/5be9c0e156f0499716042aae68d1965f to your computer and use it in GitHub Desktop.

Select an option

Save mu-hun/5be9c0e156f0499716042aae68d1965f to your computer and use it in GitHub Desktop.
Grade-Point-Average parse demo for dreamy.jejunu.ac.kr
import request from 'request'
const student_no = 2018123456
const student_pw = 'PASSWORD'
const BaseURL = 'https://dreamy.jejunu.ac.kr'
const rejectUnauthorized = false
const headers = {
'User-Agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:70.0) Gecko/20100101 Firefox/70.0',
}
const base64Encode = (data: string | object) => {
let Bf: Buffer
if (typeof data === 'string') Bf = Buffer.from(data)
else Bf = Buffer.from(JSON.stringify(data))
return Bf.toString('base64')
}
const getCookie = (id: string, pw: string) =>
new Promise<string[]>((res, rej) => {
request.post(
`${BaseURL}/frame/sysUser.do?next=`,
{
rejectUnauthorized,
form: { tmpu: base64Encode(id), tmpw: base64Encode(pw) },
headers,
},
(err, { headers }, body: string) => {
res(headers['set-cookie'])
}
)
})
const main = async () => {
const cookie = await getCookie(student_no.toString(), student_pw)
request.post(
`${BaseURL}/hjju/hj/sta_hj_1010q.jejunu`,
{
rejectUnauthorized,
form: { mode: 'doValue', student_no },
headers: Object.assign(headers, {
Cookie: `${cookie[0].substring(0, 19)} ${cookie[1]}`,
}),
},
// @ts-ignore: show grade-point-average
(err, res, body) => console.log(JSON.parse(body).CREDIT_SUBJECT[0].avg_mark)
)
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment