srtrain
v1.0.0
Published
Node.js SRT train unofficial SDK
Downloads
3
Maintainers
Readme
Srtrain
Node.js SRT train unofficial SDK
Install
Use NPM
$ npm install srtrain
Or Yarn
$ yarn add srtrain
Usage:
import moment from 'moment';
import { SRT, SRTPassengers, SRTPrioritySeatType } from 'srtrain';
async function main() {
const srt = new SRT();
await srt.login({
userId: '010-0000-0000',
password: 'P4ssw0rd',
});
const trains = await srt.find({
departureStation: srt.getStation('수서'),
arrivalStation: srt.getStation('부산'),
date: moment().add(1, 'days').startOf('day'),
all: true,
});
if (trains.length <= 0) {
console.log('No trains found.');
return;
}
const [train] = trains;
const passengers = [SRTPassengers.Adult(1)];
const prioritySeatType = SRTPrioritySeatType.GENERAL_FIRST;
const reservation = await train.reserve({ passengers, prioritySeatType });
console.log('Successfully reserved train.');
console.log(reservation);
const tickets = await reservation.getTickets();
console.log('Successfully fetched tickets.');
console.log(tickets);
await reservation.cancel();
console.log('Successfully cancelled reservation.');
}
main();
License
Copyright (c) 2023 Daniel Uhm.