diff --git a/SRT/netfunnel.py b/SRT/netfunnel.py index 8a8c24b..f3759aa 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,10 @@ 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_COMPLETED, + ]: raise SRTNetFunnelError(f"Failed to complete NetFunnel: {netfunnel_resp}") def _get_timestamp_for_netfunnel(self): diff --git a/SRT/passenger.py b/SRT/passenger.py index cde41b9..be8a0d5 100644 --- a/SRT/passenger.py +++ b/SRT/passenger.py @@ -78,22 +78,22 @@ 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" + data[f"psrmClCd{psgidx}"] = "2" if special_seat else "1" return data diff --git a/SRT/srt.py b/SRT/srt.py index d70385e..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: # 일반실만 @@ -450,21 +447,12 @@ def _reserve( "dptDt1": train.dep_date, # 출발일자1 (열차 목록 값) "dptTm1": train.dep_time, # 출발일자1 (열차 목록 값) "arvTm1": train.arr_time, # 도착일자1 (열차 목록 값) - "totPrnb": passengersCount, # 승차인원 - "psgGridcnt": passengersCount, # 승차인원 - "psgTpCd1": passengersCount, # 승차인원 - "psgInfoPerPrnb1": passengersCount, # 승차인원 "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", # 방향좌석속성코드 - "locSeatAttCd1": "000", # 위치좌석속성코드1 - "rqSeatAttCd1": "015", # 요구좌석속성코드1 "mblPhone": mblPhone, } @@ -472,7 +460,7 @@ def _reserve( if jobid == RESERVE_JOBID["PERSONAL"]: data.update( { - "reserveType": "1", + "reserveType": "11", } ) diff --git a/tests/test_passenger.py b/tests/test_passenger.py index c19e1a5..8dfb2db 100644 --- a/tests/test_passenger.py +++ b/tests/test_passenger.py @@ -20,10 +20,10 @@ 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["psgTpCd5"] == "5" - assert data["psgInfoPerPrnb5"] == "2" + assert data["psgTpCd1"] == "5" + assert data["psgInfoPerPrnb1"] == "2" + assert data["psgTpCd2"] == "1" + assert data["psgInfoPerPrnb2"] == "1" 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["psgTpCd1"] == "3" + assert data["psgInfoPerPrnb1"] == "1" assert data["psgTpCd2"] == "2" assert data["psgInfoPerPrnb2"] == "1" - assert data["psgTpCd3"] == "3" + assert data["psgTpCd3"] == "4" assert data["psgInfoPerPrnb3"] == "1"