fix:issue606
This commit is contained in:
30
config/StatusCode.py
Normal file
30
config/StatusCode.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class StatusCode(Enum):
|
||||
"""
|
||||
程序返回状态码
|
||||
name: 状态名
|
||||
value: 状态值
|
||||
description: 状态描述
|
||||
"""
|
||||
OK = 0, u"正常"
|
||||
RetryTimeHasReachedMaxValue = 101, u"重试次数达到上限"
|
||||
CdnListEmpty = 102, u"cdn列表为空"
|
||||
UnknownError = 999, u"未知错误"
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
obj = object.__new__(cls)
|
||||
obj._value_ = args[0]
|
||||
return obj
|
||||
|
||||
def __init__(self, _: str, description: str = None):
|
||||
self._description_ = description
|
||||
|
||||
def __str__(self):
|
||||
return str(self.value)
|
||||
|
||||
# description is read-only
|
||||
@property
|
||||
def description(self):
|
||||
return self._description_
|
||||
@@ -6,8 +6,6 @@ class ticket(object):
|
||||
QUERY_C = u"查询到有余票,尝试提交订单"
|
||||
QUERY_IN_BLACK_LIST = u"该车次{} 正在被关小黑屋,跳过此车次"
|
||||
|
||||
SUCCESS_CODE = 000000
|
||||
FAIL_CODE = 999999
|
||||
AUTO_SUBMIT_ORDER_REQUEST_C = u"提交订单成功"
|
||||
AUTO_SUBMIT_ORDER_REQUEST_F = u"提交订单失败,重新刷票中"
|
||||
AUTO_SUBMIT_NEED_CODE = u"需要验证码"
|
||||
|
||||
@@ -13,6 +13,7 @@ from config import urlConf, configCommon
|
||||
from config.TicketEnmu import ticket
|
||||
from config.configCommon import seat_conf_2, seat_conf
|
||||
from config.getCookie import getDrvicesID
|
||||
from config.StatusCode import StatusCode
|
||||
from init.login import GoLogin
|
||||
from inter.AutoSubmitOrderRequest import autoSubmitOrderRequest
|
||||
from inter.ChechFace import chechFace
|
||||
@@ -116,6 +117,9 @@ class select:
|
||||
configCommon.checkSleepTime(self) # 防止网上启动晚上到点休眠
|
||||
self.login.go_login()
|
||||
|
||||
def read_cdn_list(self):
|
||||
self.cdn_list = open_cdn_file("filter_cdn_list")
|
||||
|
||||
def main(self):
|
||||
l = liftTicketInit(self)
|
||||
l.reqLiftTicketInit()
|
||||
@@ -161,6 +165,17 @@ class select:
|
||||
ticke_peoples_num=len(TickerConfig.TICKET_PEOPLES),
|
||||
)
|
||||
queryResult = q.sendQuery()
|
||||
|
||||
# 检查结果状态
|
||||
status_value = queryResult.get("code", StatusCode.OK.value)
|
||||
if status_value != StatusCode.OK.value:
|
||||
# 状态出错
|
||||
if status_value == StatusCode.CdnListEmpty.value:
|
||||
from agency.cdn_utils import filterCdn
|
||||
filterCdn()
|
||||
self.read_cdn_list()
|
||||
continue
|
||||
|
||||
# 查询接口
|
||||
if queryResult.get("status"):
|
||||
train_no = queryResult.get("train_no", "")
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import json
|
||||
|
||||
from config.TicketEnmu import ticket
|
||||
from config.StatusCode import StatusCode
|
||||
from myException.PassengerUserException import PassengerUserException
|
||||
import wrapcache
|
||||
import TickerConfig
|
||||
@@ -116,7 +117,7 @@ class getPassengerDTOs:
|
||||
"passengerTicketStrList": set_type + "," + ",".join(passengerTicketStrList),
|
||||
"passengerTicketStrByAfterLate": "".join(tickers),
|
||||
"oldPassengerStr": "".join(oldPassengerStr),
|
||||
"code": ticket.SUCCESS_CODE,
|
||||
"code": StatusCode.OK.value,
|
||||
"set_type": set_type,
|
||||
"status": True,
|
||||
"user_info": user_info,
|
||||
|
||||
@@ -6,6 +6,7 @@ from config import urlConf
|
||||
from config.TicketEnmu import ticket
|
||||
from myUrllib.httpUtils import HTTPClient
|
||||
from config.configCommon import seat_conf_2
|
||||
from config.StatusCode import StatusCode
|
||||
import TickerConfig
|
||||
|
||||
|
||||
@@ -70,6 +71,10 @@ class query:
|
||||
select_url["req_url"] = select_url["req_url"].format(station_date, self.from_station, self.to_station,
|
||||
self.session.queryUrl)
|
||||
station_ticket = self.httpClint.send(select_url)
|
||||
status_code = station_ticket.get("code", StatusCode.OK.value)
|
||||
if status_code != StatusCode.OK.value:
|
||||
return station_ticket
|
||||
|
||||
value = station_ticket.get("data", "")
|
||||
if not value:
|
||||
print(u'{0}-{1} 车次坐席查询为空,查询url: https://kyfw.12306.cn{2}, 可以手动查询是否有票'.format(
|
||||
@@ -146,7 +151,7 @@ class query:
|
||||
"seat": seat,
|
||||
"leftTicket": leftTicket,
|
||||
"train_location": train_location,
|
||||
"code": ticket.SUCCESS_CODE,
|
||||
"code": StatusCode.OK.value,
|
||||
"is_more_ticket_num": is_more_ticket_num,
|
||||
"cdn": self.httpClint.cdn,
|
||||
"status": True,
|
||||
@@ -182,7 +187,7 @@ class query:
|
||||
else:
|
||||
print(u"车次配置信息有误,或者返回数据异常,请检查 {}".format(station_ticket))
|
||||
self.session.flag = False
|
||||
return {"code": ticket.FAIL_CODE, "status": False, "cdn": self.httpClint.cdn, }
|
||||
return {"code": StatusCode.UnknownError.value, "status": False, "cdn": self.httpClint.cdn, }
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -9,6 +9,7 @@ from fake_useragent import UserAgent
|
||||
import TickerConfig
|
||||
from agency.agency_tools import proxy
|
||||
from config import logger
|
||||
from config.StatusCode import StatusCode
|
||||
|
||||
|
||||
def _set_header_default():
|
||||
@@ -132,7 +133,8 @@ class HTTPClient(object):
|
||||
s_time = urls.get("s_time", 0)
|
||||
is_cdn = urls.get("is_cdn", False)
|
||||
is_test_cdn = urls.get("is_test_cdn", False)
|
||||
error_data = {"code": 99999, "message": u"重试次数达到上限"}
|
||||
retry_error = StatusCode.RetryTimeHasReachedMaxValue
|
||||
error_data = {"code": retry_error.value, "message": retry_error.description}
|
||||
if data:
|
||||
method = "post"
|
||||
self.setHeaders({"Content-Length": "{0}".format(len(data))})
|
||||
@@ -195,7 +197,12 @@ class HTTPClient(object):
|
||||
u"url: {} 返回参数为空".format(urls["req_url"]))
|
||||
if self.cdnList:
|
||||
# 如果下单或者登陆出现cdn 302的情况,立马切换cdn
|
||||
url_host = self.cdnList.pop(random.randint(0, 4))
|
||||
if len(self.cdnList) >= 5:
|
||||
url_host = self.cdnList.pop(random.randint(0, 4))
|
||||
else:
|
||||
cdn_empty_error = StatusCode.CdnListEmpty
|
||||
print(f"出错:{cdn_empty_error.description}")
|
||||
return {"code": cdn_empty_error.value, "message": cdn_empty_error.description}
|
||||
continue
|
||||
else:
|
||||
sleep(urls["re_time"])
|
||||
|
||||
Reference in New Issue
Block a user