From 93c38f0e253b3bdc140ebca81481f59c6ba15b33 Mon Sep 17 00:00:00 2001 From: Chanhong Min Date: Mon, 16 Dec 2024 21:41:14 +0900 Subject: [PATCH 01/16] add ALREADY_COMPLETED status pass "already completed" error (it occurs trying _set_complete method multiple times in short durartion) --- SRT/netfunnel.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SRT/netfunnel.py b/SRT/netfunnel.py index 8a8c24b..b63caf4 100644 --- a/SRT/netfunnel.py +++ b/SRT/netfunnel.py @@ -17,6 +17,7 @@ class NetFunnelHelper: WAIT_STATUS_PASS = "200" # No need to wait WAIT_STATUS_FAIL = "201" # Need to wait + ALREADY_COMPLETED = "502" # already completed(set-complete) DEFAULT_HEADERS = { "User-Agent": USER_AGENT, @@ -161,7 +162,7 @@ def _set_complete(self, key: str): raise SRTNetFunnelError(e) from e netfunnel_resp = NetFunnelResponse.parse(resp.text) - if netfunnel_resp.get("status") != self.WAIT_STATUS_PASS: + if netfunnel_resp.get("status") not in [self.WAIT_STATUS_PASS, self.ALREADY_COPLETED]: raise SRTNetFunnelError(f"Failed to complete NetFunnel: {netfunnel_resp}") def _get_timestamp_for_netfunnel(self): From 09aa435a9d5044787e54b7d42a214ebf1ee0381c Mon Sep 17 00:00:00 2001 From: Chanhong Min Date: Mon, 16 Dec 2024 21:42:42 +0900 Subject: [PATCH 02/16] Update passenger.py --- SRT/passenger.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/SRT/passenger.py b/SRT/passenger.py index cde41b9..096b886 100644 --- a/SRT/passenger.py +++ b/SRT/passenger.py @@ -78,20 +78,20 @@ def get_passenger_dict( "totPrnb": Passenger.total_count(passengers), "psgGridcnt": str(len(passengers)), } - for _, passenger in enumerate(passengers): - code = passenger.type_code - data[f"psgTpCd{code}"] = passenger.type_code - data[f"psgInfoPerPrnb{code}"] = str(passenger.count) + for idx, passenger in enumerate(passengers): + psgidx = idx + 1 + data[f"psgTpCd{psgidx}"] = passenger.type_code + data[f"psgInfoPerPrnb{psgidx}"] = str(passenger.count) # seat location ('000': 기본, '012': 창측, '013': 복도측) - data[f"locSeatAttCd{code}"] = WINDOW_SEAT[window_seat] + data[f"locSeatAttCd{psgidx}"] = WINDOW_SEAT[window_seat] # seat requirement ('015': 일반, '021': 휠체어) # TODO: 선택 가능하게 - data[f"rqSeatAttCd{code}"] = "015" + data[f"rqSeatAttCd{psgidx}"] = "015" # seat direction ('009': 정방향) - data[f"dirSeatAttCd{code}"] = "009" + data[f"dirSeatAttCd{psgidx}"] = "009" - data[f"smkSeatAttCd{code}"] = "000" - data[f"etcSeatAttCd{code}"] = "000" + data[f"smkSeatAttCd{psgidx}"] = "000" + data[f"etcSeatAttCd{psgidx}"] = "000" # seat type: ('1': 일반실, '2': 특실) data[f"psrmClCd{code}"] = "2" if special_seat else "1" From 053c3d2fe1824f30278f4419cb9131cce0418d4d Mon Sep 17 00:00:00 2001 From: Chanhong Min Date: Mon, 16 Dec 2024 21:46:05 +0900 Subject: [PATCH 03/16] Update reserve basic payload data change description and default value of "psgTpCd1", "psgInfoPerPrnb1" --- SRT/srt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SRT/srt.py b/SRT/srt.py index d70385e..b4c6252 100644 --- a/SRT/srt.py +++ b/SRT/srt.py @@ -452,8 +452,8 @@ def _reserve( "arvTm1": train.arr_time, # 도착일자1 (열차 목록 값) "totPrnb": passengersCount, # 승차인원 "psgGridcnt": passengersCount, # 승차인원 - "psgTpCd1": passengersCount, # 승차인원 - "psgInfoPerPrnb1": passengersCount, # 승차인원 + "psgTpCd1": "0", # 승객종류1 인원수 (psgTpCd1~5) + "psgInfoPerPrnb1": "0", # 승객종류1 인원수 (psgInfoPerPrnb1~5) "trnNo1": "%05d" % int(train.train_number), # 열차번호1 (열차 목록 값) "runDt1": train.dep_date, # 운행일자1 (열차 목록 값) "psrmClCd1": "2" if is_special_seat is True else "1", From a11aa492bebca9281bba580a132beef6e86372d5 Mon Sep 17 00:00:00 2001 From: Chanhong Min Date: Mon, 16 Dec 2024 21:54:33 +0900 Subject: [PATCH 04/16] change description --- SRT/srt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SRT/srt.py b/SRT/srt.py index b4c6252..a324841 100644 --- a/SRT/srt.py +++ b/SRT/srt.py @@ -452,7 +452,7 @@ def _reserve( "arvTm1": train.arr_time, # 도착일자1 (열차 목록 값) "totPrnb": passengersCount, # 승차인원 "psgGridcnt": passengersCount, # 승차인원 - "psgTpCd1": "0", # 승객종류1 인원수 (psgTpCd1~5) + "psgTpCd1": "0", # 승객종류1 passenger.code (psgTpCd1~5, 1~5) "psgInfoPerPrnb1": "0", # 승객종류1 인원수 (psgInfoPerPrnb1~5) "trnNo1": "%05d" % int(train.train_number), # 열차번호1 (열차 목록 값) "runDt1": train.dep_date, # 운행일자1 (열차 목록 값) From d6e40162a3148f312edddba1ae4349fab14e1b3e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:02:24 +0000 Subject: [PATCH 05/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- SRT/netfunnel.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/SRT/netfunnel.py b/SRT/netfunnel.py index b63caf4..03a3717 100644 --- a/SRT/netfunnel.py +++ b/SRT/netfunnel.py @@ -17,7 +17,7 @@ class NetFunnelHelper: WAIT_STATUS_PASS = "200" # No need to wait WAIT_STATUS_FAIL = "201" # Need to wait - ALREADY_COMPLETED = "502" # already completed(set-complete) + ALREADY_COMPLETED = "502" # already completed(set-complete) DEFAULT_HEADERS = { "User-Agent": USER_AGENT, @@ -162,7 +162,10 @@ def _set_complete(self, key: str): raise SRTNetFunnelError(e) from e netfunnel_resp = NetFunnelResponse.parse(resp.text) - if netfunnel_resp.get("status") not in [self.WAIT_STATUS_PASS, self.ALREADY_COPLETED]: + if netfunnel_resp.get("status") not in [ + self.WAIT_STATUS_PASS, + self.ALREADY_COPLETED, + ]: raise SRTNetFunnelError(f"Failed to complete NetFunnel: {netfunnel_resp}") def _get_timestamp_for_netfunnel(self): From 75c1d7bb9b2e70b2ff75cb71b504993513410d23 Mon Sep 17 00:00:00 2001 From: Chanhong Min Date: Mon, 16 Dec 2024 22:05:55 +0900 Subject: [PATCH 06/16] change typo --- SRT/netfunnel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SRT/netfunnel.py b/SRT/netfunnel.py index 03a3717..f3759aa 100644 --- a/SRT/netfunnel.py +++ b/SRT/netfunnel.py @@ -164,7 +164,7 @@ def _set_complete(self, key: str): netfunnel_resp = NetFunnelResponse.parse(resp.text) if netfunnel_resp.get("status") not in [ self.WAIT_STATUS_PASS, - self.ALREADY_COPLETED, + self.ALREADY_COMPLETED, ]: raise SRTNetFunnelError(f"Failed to complete NetFunnel: {netfunnel_resp}") From 092fd5c86fc0ca5088b7562db74a6189d5a306cc Mon Sep 17 00:00:00 2001 From: Chanhong Min Date: Mon, 16 Dec 2024 22:08:49 +0900 Subject: [PATCH 07/16] code -> psgidx --- SRT/passenger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SRT/passenger.py b/SRT/passenger.py index 096b886..be8a0d5 100644 --- a/SRT/passenger.py +++ b/SRT/passenger.py @@ -93,7 +93,7 @@ def get_passenger_dict( data[f"smkSeatAttCd{psgidx}"] = "000" data[f"etcSeatAttCd{psgidx}"] = "000" # seat type: ('1': 일반실, '2': 특실) - data[f"psrmClCd{code}"] = "2" if special_seat else "1" + data[f"psrmClCd{psgidx}"] = "2" if special_seat else "1" return data From 6083f659e5db96a5e3519cd6616e40a5777cf356 Mon Sep 17 00:00:00 2001 From: DARAM Date: Tue, 17 Dec 2024 19:55:41 +0900 Subject: [PATCH 08/16] update reserve basic data (SeatAttCd) / change reserveType MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit smk/dir/loc/rq/etc SeatAttCd1, 2는 간편예매에서 변경되는 값으로, 일반 예매에서는 고정값 reserveType은 11로 확인됨 --- SRT/srt.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/SRT/srt.py b/SRT/srt.py index a324841..7ff2564 100644 --- a/SRT/srt.py +++ b/SRT/srt.py @@ -461,10 +461,17 @@ def _reserve( "arvStnConsOrdr1": train.arr_station_constitution_order, # 도착역구성순서1 (열차 목록 값) "dptStnRunOrdr1": train.dep_station_run_order, # 출발역운행순서1 (열차 목록 값) "arvStnRunOrdr1": train.arr_station_run_order, # 도착역운행순서1 (열차 목록 값) + #간편예매에서 사용되는 항목, 일반 승차권 예매에서는 고정값 "smkSeatAttCd1": "000", # 흡연좌석속성코드1 - "dirSeatAttCd1": "009", # 방향좌석속성코드 + "dirSeatAttCd1": "009", # 방향좌석속성코드1 "locSeatAttCd1": "000", # 위치좌석속성코드1 "rqSeatAttCd1": "015", # 요구좌석속성코드1 + "etcSeatAttCd1": "000", + "smkSeatAttCd2": "000", # 흡연좌석속성코드2 + "dirSeatAttCd2": "009", # 방향좌석속성코드2 + "locSeatAttCd2": "000", # 위치좌석속성코드2 + "rqSeatAttCd2": "015", # 요구좌석속성코드2 + "etcSeatAttCd2": "000", "mblPhone": mblPhone, } @@ -472,7 +479,7 @@ def _reserve( if jobid == RESERVE_JOBID["PERSONAL"]: data.update( { - "reserveType": "1", + "reserveType": "11", } ) From 23493dcaf28abfa1b61ad6b050f216613ec21356 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 17 Dec 2024 10:56:36 +0000 Subject: [PATCH 09/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- SRT/srt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SRT/srt.py b/SRT/srt.py index 7ff2564..9c0241f 100644 --- a/SRT/srt.py +++ b/SRT/srt.py @@ -461,7 +461,7 @@ def _reserve( "arvStnConsOrdr1": train.arr_station_constitution_order, # 도착역구성순서1 (열차 목록 값) "dptStnRunOrdr1": train.dep_station_run_order, # 출발역운행순서1 (열차 목록 값) "arvStnRunOrdr1": train.arr_station_run_order, # 도착역운행순서1 (열차 목록 값) - #간편예매에서 사용되는 항목, 일반 승차권 예매에서는 고정값 + # 간편예매에서 사용되는 항목, 일반 승차권 예매에서는 고정값 "smkSeatAttCd1": "000", # 흡연좌석속성코드1 "dirSeatAttCd1": "009", # 방향좌석속성코드1 "locSeatAttCd1": "000", # 위치좌석속성코드1 From bf6852872a7f80876294f9705076afd0d7edc143 Mon Sep 17 00:00:00 2001 From: DARAM Date: Mon, 23 Dec 2024 12:33:12 +0900 Subject: [PATCH 10/16] remove unnecessary data in reserve payload --- SRT/srt.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/SRT/srt.py b/SRT/srt.py index 9c0241f..e28c62b 100644 --- a/SRT/srt.py +++ b/SRT/srt.py @@ -450,28 +450,12 @@ def _reserve( "dptDt1": train.dep_date, # 출발일자1 (열차 목록 값) "dptTm1": train.dep_time, # 출발일자1 (열차 목록 값) "arvTm1": train.arr_time, # 도착일자1 (열차 목록 값) - "totPrnb": passengersCount, # 승차인원 - "psgGridcnt": passengersCount, # 승차인원 - "psgTpCd1": "0", # 승객종류1 passenger.code (psgTpCd1~5, 1~5) - "psgInfoPerPrnb1": "0", # 승객종류1 인원수 (psgInfoPerPrnb1~5) "trnNo1": "%05d" % int(train.train_number), # 열차번호1 (열차 목록 값) "runDt1": train.dep_date, # 운행일자1 (열차 목록 값) - "psrmClCd1": "2" if is_special_seat is True else "1", "dptStnConsOrdr1": train.dep_station_constitution_order, # 출발역구성순서1 (열차 목록 값) "arvStnConsOrdr1": train.arr_station_constitution_order, # 도착역구성순서1 (열차 목록 값) "dptStnRunOrdr1": train.dep_station_run_order, # 출발역운행순서1 (열차 목록 값) "arvStnRunOrdr1": train.arr_station_run_order, # 도착역운행순서1 (열차 목록 값) - # 간편예매에서 사용되는 항목, 일반 승차권 예매에서는 고정값 - "smkSeatAttCd1": "000", # 흡연좌석속성코드1 - "dirSeatAttCd1": "009", # 방향좌석속성코드1 - "locSeatAttCd1": "000", # 위치좌석속성코드1 - "rqSeatAttCd1": "015", # 요구좌석속성코드1 - "etcSeatAttCd1": "000", - "smkSeatAttCd2": "000", # 흡연좌석속성코드2 - "dirSeatAttCd2": "009", # 방향좌석속성코드2 - "locSeatAttCd2": "000", # 위치좌석속성코드2 - "rqSeatAttCd2": "015", # 요구좌석속성코드2 - "etcSeatAttCd2": "000", "mblPhone": mblPhone, } From e09f2d593f8e94e98a54c75388c12e200f60b18c Mon Sep 17 00:00:00 2001 From: DARAM Date: Mon, 23 Dec 2024 12:40:24 +0900 Subject: [PATCH 11/16] remove unused variable(passengersCount) --- SRT/srt.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/SRT/srt.py b/SRT/srt.py index e28c62b..eff4767 100644 --- a/SRT/srt.py +++ b/SRT/srt.py @@ -411,9 +411,6 @@ def _reserve( passengers = [Adult()] passengers = Passenger.combine(passengers) - if passengers is not None: - passengersCount = len(passengers) - # 일반식 / 특실 좌석 선택 옵션에 따라 결정. is_special_seat = None if special_seat == SeatType.GENERAL_ONLY: # 일반실만 From 14b67cfdb869b085eb7733c81058098e132e662a Mon Sep 17 00:00:00 2001 From: DARAM Date: Mon, 23 Dec 2024 12:52:54 +0900 Subject: [PATCH 12/16] Update test_passenger.py --- tests/test_passenger.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_passenger.py b/tests/test_passenger.py index c19e1a5..8b19b45 100644 --- a/tests/test_passenger.py +++ b/tests/test_passenger.py @@ -22,8 +22,8 @@ def test_get_passenger_dict(): assert data["psgGridcnt"] == "2" assert data["psgTpCd1"] == "1" assert data["psgInfoPerPrnb1"] == "1" - assert data["psgTpCd5"] == "5" - assert data["psgInfoPerPrnb5"] == "2" + assert data["psgTpCd2"] == "5" + assert data["psgInfoPerPrnb2"] == "2" passengers2 = [ Senior(), @@ -36,9 +36,9 @@ def test_get_passenger_dict(): data = Passenger.get_passenger_dict(passengers2) assert data["totPrnb"] == "3" assert data["psgGridcnt"] == "3" - assert data["psgTpCd4"] == "4" - assert data["psgInfoPerPrnb4"] == "1" - assert data["psgTpCd2"] == "2" + assert data["psgTpCd1"] == "2" + assert data["psgInfoPerPrnb1"] == "1" + assert data["psgTpCd2"] == "3" assert data["psgInfoPerPrnb2"] == "1" - assert data["psgTpCd3"] == "3" + assert data["psgTpCd3"] == "4" assert data["psgInfoPerPrnb3"] == "1" From b1bb51adda417b9d51684e4c0e52a81c396dc54a Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Mon, 23 Dec 2024 22:24:15 +0900 Subject: [PATCH 13/16] Update test_passenger.py --- tests/test_passenger.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_passenger.py b/tests/test_passenger.py index 8b19b45..89792f6 100644 --- a/tests/test_passenger.py +++ b/tests/test_passenger.py @@ -20,9 +20,9 @@ def test_get_passenger_dict(): data = Passenger.get_passenger_dict(passengers) assert data["totPrnb"] == "3" assert data["psgGridcnt"] == "2" - assert data["psgTpCd1"] == "1" - assert data["psgInfoPerPrnb1"] == "1" - assert data["psgTpCd2"] == "5" + assert data["psgTpCd1"] == "5" + assert data["psgInfoPerPrnb1"] == "2" + assert data["psgTpCd2"] == "1" assert data["psgInfoPerPrnb2"] == "2" passengers2 = [ From c21d4ecede00a7d2f1dabd9e8b1509ce4a055b30 Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Mon, 23 Dec 2024 22:25:24 +0900 Subject: [PATCH 14/16] Update test_passenger.py --- tests/test_passenger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_passenger.py b/tests/test_passenger.py index 89792f6..3f828ec 100644 --- a/tests/test_passenger.py +++ b/tests/test_passenger.py @@ -23,7 +23,7 @@ def test_get_passenger_dict(): assert data["psgTpCd1"] == "5" assert data["psgInfoPerPrnb1"] == "2" assert data["psgTpCd2"] == "1" - assert data["psgInfoPerPrnb2"] == "2" + assert data["psgInfoPerPrnb2"] == "1" passengers2 = [ Senior(), From 217f1363b0f6f5ae78a85528f9d33878026e8ee1 Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Mon, 23 Dec 2024 22:27:51 +0900 Subject: [PATCH 15/16] Update test_passenger.py --- tests/test_passenger.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_passenger.py b/tests/test_passenger.py index 3f828ec..ca9fe27 100644 --- a/tests/test_passenger.py +++ b/tests/test_passenger.py @@ -36,9 +36,9 @@ def test_get_passenger_dict(): data = Passenger.get_passenger_dict(passengers2) assert data["totPrnb"] == "3" assert data["psgGridcnt"] == "3" - assert data["psgTpCd1"] == "2" + assert data["psgTpCd1"] == "3" assert data["psgInfoPerPrnb1"] == "1" - assert data["psgTpCd2"] == "3" + assert data["psgTpCd2"] == "4" assert data["psgInfoPerPrnb2"] == "1" - assert data["psgTpCd3"] == "4" + assert data["psgTpCd3"] == "2" assert data["psgInfoPerPrnb3"] == "1" From 75bf5cc0944ab39ec1328a64497530636ffc81a0 Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Mon, 23 Dec 2024 22:30:33 +0900 Subject: [PATCH 16/16] Update test_passenger.py --- tests/test_passenger.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_passenger.py b/tests/test_passenger.py index ca9fe27..8dfb2db 100644 --- a/tests/test_passenger.py +++ b/tests/test_passenger.py @@ -38,7 +38,7 @@ def test_get_passenger_dict(): assert data["psgGridcnt"] == "3" assert data["psgTpCd1"] == "3" assert data["psgInfoPerPrnb1"] == "1" - assert data["psgTpCd2"] == "4" + assert data["psgTpCd2"] == "2" assert data["psgInfoPerPrnb2"] == "1" - assert data["psgTpCd3"] == "2" + assert data["psgTpCd3"] == "4" assert data["psgInfoPerPrnb3"] == "1"