-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·54 lines (42 loc) · 1.19 KB
/
index.js
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
54
#!/usr/bin/env node
const axios = require('axios')
const ora = require('ora')
const chalk = require('chalk')
const Table = require('cli-table')
const args = process.argv
const log = console.log
const studentId = args[2]
const url = `https://uesc.foxfizz.com/api/v1/daa/uesc.json?student_id=${studentId}`
const handleData = data =>
data.map(item =>
[item.date, item.day, item.shift, item.name, item.id_number, item.room]
)
const createTable = data => {
const table = new Table({
head: ['Date', 'Day', 'Shift', 'Name', 'Number ID', 'Room'],
colWidths: [15, 6, 8, 50, 12, 12]
})
const tableData = handleData(data)
for (const tinyData of tableData) {
table.push(tinyData)
}
log(table.toString())
}
const app = async () => {
const spinner = ora('Loading your exam schedule...').start()
try {
const { data } = await axios.get(url)
const name = '🎓 ' + data.name
const id = '🆔 ' + studentId
const message = `
${chalk.yellowBright(name)}
${chalk.greenBright(id)}
`
spinner.succeed('Done')
log(message)
createTable(data.es)
} catch(err) {
spinner.fail('Coundn\'t load your exam schedule.\nPlease try again!')
}
}
app()