-
Notifications
You must be signed in to change notification settings - Fork 4
/
shell.js
executable file
·41 lines (34 loc) · 1.28 KB
/
shell.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
#!/usr/bin/env node
require('dotenv').config()
const moment = require('moment-range').extendMoment(require('moment-timezone'))
const async = require('async')
const lifebot = require('./lib/lifebot')
let dates = []
switch (process.argv.length) {
case 3:
let date = moment(process.argv[2], 'YYYY-MM-DD').tz(process.env.TIMEZONE)
if (!date.isValid()) throw new Error(`invalid date ${process.argv[2]}`)
dates.push(date)
break
case 4:
let range = [
moment(process.argv[2], 'YYYY-MM-DD').tz(process.env.TIMEZONE),
moment(process.argv[3], 'YYYY-MM-DD').tz(process.env.TIMEZONE)
]
if (!range[0].isValid()) throw new Error(`invalid date ${process.argv[2]}`)
if (!range[1].isValid()) throw new Error(`invalid date ${process.argv[3]}`)
if (range[1].isBefore(range[0])) {
range.reverse()
}
dates = Array.from(moment.range(range[0], range[1]).by('day'))
break
default:
dates.push(moment().tz(process.env.TIMEZONE))
}
async.eachSeries(dates, (date, done) => {
console.log(`updating spreadsheet for ${date.format('YYYY-MM-DD')}`)
lifebot.updateSpreadsheetWithLatestData(date, done)
}, error => {
if (error) throw error
console.log('update complete')
})