-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·67 lines (54 loc) · 1.48 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
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
'use strict'
const metrospStatus = require('metrosp-status')
const { green, yellow, red, gray, bold } = require('chalk')
const figures = require('figures')
const meow = require('meow')
const updateNotifier = require('update-notifier')
const lastTweet = require('last-tweet')
const shoutMessage = require('shout-message')
const cli = meow(
`
Usage:
$ metrosp-status Show metrosp status
Options:
-h, --help Show help options
-v, --version Show version
`,
{
alias: {
h: 'help',
v: 'version'
}
}
)
updateNotifier({ pkg: cli.pkg }).notify()
Promise.all([metrospStatus(), lastTweet('metrosp_oficial')]).then(result => {
const lines = result[0]
const { tweet, time, user } = result[1]
const cleanTweet = tweet.substring(
tweet.indexOf('#metrosp') + 11,
tweet.length - 1
)
shoutMessage(`${bold('@' + user)}: ${cleanTweet}. ${gray('[' + time + ']')}
`)
lines.map(({ linha, status }) => {
let bulletStatus
switch (status) {
case 'Normal':
bulletStatus = green(figures('●'))
break
case 'Parcial':
bulletStatus = yellow(figures('●'))
break
case 'Parada':
bulletStatus = red(figures('●'))
break
default:
bulletStatus = green(figures('●'))
break
}
const operation = gray(`(${status.toLowerCase()})`)
return console.log(`${bulletStatus} ${bold(linha)} ${operation}`)
})
})