This repository has been archived by the owner on Jun 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
152 additions
and
78 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,5 @@ node_modules/ | |
dist/ | ||
.cache/ | ||
package-lock.json | ||
severless/ | ||
cloudbase* | ||
conf* | ||
/conf.toml |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# 学校英文简称 | ||
school = "whpu" | ||
|
||
# 使用学校地址签到 | ||
[[users]] | ||
username = "用户名" | ||
password = "密码" | ||
alias = "简称" | ||
addr = "" | ||
|
||
# 使用随机地址在家签到 | ||
[[users]] | ||
username = "用户名" | ||
password = "密码" | ||
alias = "简称" | ||
addr = "home" | ||
|
||
# 使用自定义地址在家签到 | ||
[[users]] | ||
username = "用户名" | ||
password = "密码" | ||
alias = "简称" | ||
addr = ["经度", "纬度", "实际地址"] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Reset $XDG_CONFIG_HOME | ||
process.env.XDG_CONFIG_HOME = '/tmp' | ||
const { handleCookie, signApp, conf } = require('@beetcb/cea') | ||
|
||
// Grab users array | ||
const users = conf.get('users') | ||
// Grab school info | ||
const school = conf.get('school') | ||
|
||
function loadConf() { | ||
const path = './conf.toml' | ||
if (fs.existsSync(path)) { | ||
const doc = tomlParse(fs.readFileSync(path, 'utf8')) | ||
if (!conf.get('school')) | ||
return doc.users | ||
} | ||
} | ||
|
||
async function signIn() { | ||
const logs = {} | ||
// sign in asynchronizedly with promise all and diff instance of signApp class | ||
await Promise.all( | ||
users.map(async i => { | ||
const cookie = i.cookie | ||
? { campusphere: i.cookie } | ||
: conf.get(`cookie.${i.alias || i.username}`) | ||
const sign = new signApp(school, i) | ||
await sign.signInfo(cookie) | ||
await sign.signWithForm() | ||
logs[i.alias || i.id] = sign.result | ||
}) | ||
) | ||
return logs | ||
} | ||
|
||
async function handler() { | ||
// Log in and save cookie to conf, using conf.get('cookie') to get them | ||
await handleCookie() | ||
// Sign in | ||
const logs = await signIn() | ||
// Log out config path | ||
console.table(logs) | ||
} | ||
|
||
exports.main = handler |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "severless", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@beetcb/cea": "^1.1.5" | ||
} | ||
} |