2021-11-28 19:40:16 +01:00
|
|
|
import dayjs from 'dayjs'
|
2022-03-29 22:41:44 +02:00
|
|
|
import { v4 } from 'uuid'
|
|
|
|
|
import { Logger, LogLevel } from './common/logger'
|
2021-11-28 19:40:16 +01:00
|
|
|
import { ReservationRequest } from './common/request'
|
2021-11-24 00:00:22 +01:00
|
|
|
import { Reservation } from './common/reservation'
|
|
|
|
|
import { Runner } from './common/runner'
|
2021-11-15 11:28:39 +01:00
|
|
|
|
2021-11-28 19:40:16 +01:00
|
|
|
const run = async (request: ReservationRequest) => {
|
2022-03-29 22:41:44 +02:00
|
|
|
Logger.instantiate('local', v4(), LogLevel.DEBUG);
|
2021-11-28 19:40:16 +01:00
|
|
|
const { username, password, dateRange, opponent } = request
|
|
|
|
|
const reservation = new Reservation(dateRange, opponent)
|
2021-11-15 11:28:39 +01:00
|
|
|
|
2021-11-28 19:40:16 +01:00
|
|
|
const runner = new Runner(username, password, [reservation])
|
2021-11-15 11:28:39 +01:00
|
|
|
await runner.run({ headless: false })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get supplied args
|
|
|
|
|
const args = process.argv.filter((_, index) => index >= 2)
|
2022-02-01 16:48:50 +01:00
|
|
|
if (args.length !== 9) {
|
2021-11-17 14:17:25 +01:00
|
|
|
console.error(
|
|
|
|
|
'Usage: npm run local <username> <password> <year> <month> <day> <startTime> <endTime> <opponentName> <opponentId>'
|
|
|
|
|
)
|
2021-11-15 11:28:39 +01:00
|
|
|
process.exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-17 14:17:25 +01:00
|
|
|
const [
|
|
|
|
|
username,
|
|
|
|
|
password,
|
|
|
|
|
year,
|
|
|
|
|
month,
|
|
|
|
|
day,
|
|
|
|
|
startTime,
|
|
|
|
|
endTime,
|
|
|
|
|
opponentName,
|
|
|
|
|
opponentId,
|
|
|
|
|
] = args
|
|
|
|
|
const [startHour, startMinute] = startTime
|
|
|
|
|
.split(':')
|
|
|
|
|
.map((t) => Number.parseInt(t))
|
2021-11-15 11:28:39 +01:00
|
|
|
const [endHour, endMinute] = endTime.split(':').map((t) => Number.parseInt(t))
|
|
|
|
|
|
|
|
|
|
run({
|
2021-11-15 12:32:49 +01:00
|
|
|
username: username,
|
|
|
|
|
password: password,
|
2021-11-28 19:40:16 +01:00
|
|
|
dateRange: {
|
|
|
|
|
start: dayjs(`${year}-${month}-${day}T${startHour}:${startMinute}`),
|
|
|
|
|
end: dayjs(`${year}-${month}-${day}T${endHour}:${endMinute}`),
|
|
|
|
|
},
|
2021-11-15 11:28:39 +01:00
|
|
|
opponent: {
|
|
|
|
|
name: opponentName,
|
2021-11-28 19:40:16 +01:00
|
|
|
id: opponentId,
|
2021-11-15 11:28:39 +01:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
.then(() => console.log('Success'))
|
2021-11-17 14:17:25 +01:00
|
|
|
.catch((e) => console.error(e))
|