2023-01-20 15:31:04 +01:00
|
|
|
import dayjs from '../common/dayjs'
|
2023-01-20 09:38:50 +01:00
|
|
|
import { Reservation } from '../common/reservation'
|
|
|
|
|
import { Runner } from '../common/runner'
|
2021-11-15 11:28:39 +01:00
|
|
|
|
2022-10-23 12:02:44 +02:00
|
|
|
const run = async (request: Record<string, any>) => {
|
|
|
|
|
const { user, dateRange, opponent } = request
|
|
|
|
|
const reservation = new Reservation(user, dateRange, opponent)
|
2021-11-15 11:28:39 +01:00
|
|
|
|
2022-11-29 22:51:28 +01:00
|
|
|
const runner = new Runner({ headless: false })
|
|
|
|
|
await runner.run(reservation)
|
2021-11-15 11:28:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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({
|
2022-10-23 12:02:44 +02:00
|
|
|
user: {
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
})
|
2022-10-23 11:55:47 +02:00
|
|
|
.then(() => {
|
|
|
|
|
console.log('Success')
|
|
|
|
|
process.exit(0)
|
|
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
console.error(e)
|
|
|
|
|
process.exit(1)
|
|
|
|
|
})
|