Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
feat: init school addr as well
Browse files Browse the repository at this point in the history
  • Loading branch information
beetcb committed Dec 21, 2020
1 parent 45c9f39 commit 924cc9d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ if (!users) {
log.error('未找到用户,请运行 ./init.js -u 配置')
process.exit(1)
}
log.object(users)

/**
* Keys of this cookie Object:
Expand Down
15 changes: 13 additions & 2 deletions init.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class School {
).catch(err => err)

res = await JSON.parse(await res.text())

const origin = new URL(res.data[0].ampUrl).origin
school = {
origin,
Expand All @@ -169,9 +170,19 @@ class School {
getCaptcha: `${res.data[0].idsUrl}/getCaptcha.htl`,
}

// get school address & coordinates(with baidu website's ak)
const schoolName = res.data[0].name
res = await fetch(
`https://api.map.baidu.com/?qt=s&wd=${encodeURIComponent(
schoolName
)}&ak=E4805d16520de693a3fe707cdc962045&rn=10&ie=utf-8&oue=1&fromproduct=jsapi&res=api`
)
res = await res.json()
const { addr } = res.content[0]
school.addr = addr

this.conf.set('school', school)
log.success(`您的学校 ${res.data[0].name} 已完成设定`)
log.object(school)
log.success(`您的学校 ${schoolName} 已完成设定, 全局签到地址为:${addr}`)
} else {
log.warning('学校信息已配置')
}
Expand Down

0 comments on commit 924cc9d

Please sign in to comment.