Skip to main content

SRT(Super Rapid Train) wrapper for python

Project description

SRT

github actions badge Downloads Downloads

SRT(Super Rapid Train) application python wrapper

This project was inspired from korail2 of carpedm20.

Requirements

  • Python >= 3.6

Installation

pip install SRTrain

Usage

1. Login

>>> from SRT import SRT

>>> srt = SRT("1234567890", YOUR_PASSWORD) # with membership number
>>> srt = SRT("def6488@gmail.com", YOUR_PASSWORD) # with email
>>> srt = SRT("010-1234-xxxx", YOUR_PASSWORD) # with phone number

use verbose option to see some debugging messages

srt = SRT("010-1234-xxxx", YOUR_PASSWORD, verbose=True)

2. Searching trains

use search_train method.

  • dep : A departure station in Korean ex) '수서'
  • arr : A arrival station in Korean ex) '부산'
  • date : (optional) (default: today) A departure date in yyyyMMdd format
  • time : (optional) (default: 000000) A departure time in hhmmss format
  • available_only: (optional) (default: True) return trains with available seats only
>>> dep = '수서'
>>> arr = '부산'
>>> date = '20190913'
>>> time = '144000'
>>> trains = srt.search_train(dep, arr, date, time)
>>> trains
# [[SRT] 09월 30일, 수서~부산(15:00~17:34) 특실 예약가능, 일반실 예약가능,
# [SRT] 09월 30일, 수서~부산(15:30~18:06) 특실 예약가능, 일반실 예약가능,
# [SRT] 09월 30일, 수서~부산(16:00~18:24) 특실 매진, 일반실 예약가능,
# [SRT] 09월 30일, 수서~부산(16:25~18:45) 특실 예약가능, 일반실 예약가능, ...]

3. Making a reservation

use reserve method.

  • train : SRTTrain object returned by search_train()
  • passengers : (optional) (default: None)
  • special_seat : (optional) (default: False) True = 특실, False = 일반실 or 특실
  • window_seat : (optional) (default: None) None = 창측 or 내측, True = 창측, False = 내측
>>> trains = srt.search_train(dep, arr, date, time)
>>> reservation = srt.reserve(trains[0])
>>> reservation
# [SRT] 09월 30일, 수서~부산(15:30~18:06) 130700원(3석), 구입기한 09월 20일 23:38

>>> from passengers import Adult, Child
>>> srt.reserve(trains[1], passengers=[Adult(), Adult(), Child()])

Passenger class

WARNING: 충분히 테스트되지 않음

Highly inspired by @dotaitch's Passenger class

  • Adult
  • Child
  • Senior
  • Disability1To3
  • Disability4To6

4. Getting reserved tickets

Use get_reservations() method.

>>> reservations = srt.get_reservations()
>>> reservations
# [[SRT] 09월 30일, 수서~부산(15:30~18:06) 130700원(3석), 구입기한 09월 19일 19:11]

>>> reservations[0].tickets
# [18호차 9C (일반실) 어른/청소년 [52300원(600원 할인)],
# 18호차 10C (일반실) 어른/청소년 [52300원(600원 할인)],
# 18호차 10D (일반실) 장애 4~6급 [26100원(26800원 할인)]]

5. Canceling reservation

Use cancel method.

  • reservation: SRTreservation object returned by reserve() or returned by get_reservations()
>>> reservation = srt.reserve(train)
>>> srt.cancel(reservation)

>>> reservations = srt.get_reservations()
>>> srt.cancel(reservations[0])

Changelog

  • 0.1.3 (2019/02/15): search_train() 에서 매진되지 않은 좌석만 리턴하는 옵션을 디폴트로 추가
  • 0.1.5 (2019/02/15): 매진 확인 오류 수정
  • 1.0.0 (2019/09/13): SRT 앱 NEO 업데이트에 맞추어 API 전체 완전 수정 (#1)
  • 1.0.2 (2019/12/24): 기본 테스트 추가, CI 도구 CircleCI에서 Github Actions로 교체
  • 2.0.0 (2021/01/22): 업데이트된 SRT API URL 반영, 테스트 추가

How to test

export SRT_USERNAME=<YOUR_SRT_USERNAME>
export SRT_PASSWORD=<YOUR_SRT_PASSWORD>

# For Windows
# set SRT_USERNAME=<YOUR_SRT_USERNAME>
# set SRT_PASSWORD=<YOUR_SRT_PASSWORD>

pip install -r requirements-dev.txt

pytest SRT -v -x

# For full test
# Warning: 아래 테스트에는 실제로 표를 예약/취소하는 테스트가 포함되어 있습니다
pytest SRT -v -x --full

Sea Also

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

SRTrain-2.0.0-py3.8.egg (31.5 kB view details)

Uploaded Source

SRTrain-2.0.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file SRTrain-2.0.0-py3.8.egg.

File metadata

  • Download URL: SRTrain-2.0.0-py3.8.egg
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.6

File hashes

Hashes for SRTrain-2.0.0-py3.8.egg
Algorithm Hash digest
SHA256 90073ad36b2cbee0d990f854fa44842fd31433b2aa416a8b70882ab2ddbdf101
MD5 b84faa561f4fc36dd316d70a1efd2d84
BLAKE2b-256 b48c5e257d3910f81c9cb9dd4a0d65cf3136c6245f9cefb6666436e4541c47d6

See more details on using hashes here.

File details

Details for the file SRTrain-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: SRTrain-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for SRTrain-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3fc102dce86d4343123216350f40ede1f7cb112725b1122de2d63f93bc4eb5f7
MD5 799113f8d93be005a43e54df2aadbafe
BLAKE2b-256 a3cf63e5a6be163444ae92b2357d3e530274520266b399468cfc796b23390236

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page