From bc88a9e067c67a6efc68d8e349d1a8206773da21 Mon Sep 17 00:00:00 2001 From: kongkongyzt Date: Fri, 11 Jan 2019 00:24:45 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E6=B7=BB=E5=8A=A0pushbear=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E9=80=9A=E7=9F=A5=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/pushbearConf.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 config/pushbearConf.py diff --git a/config/pushbearConf.py b/config/pushbearConf.py new file mode 100644 index 0000000..e69de29 From 1c5ba95ff879154e9e8d75a6e54b3a02099be5a5 Mon Sep 17 00:00:00 2001 From: kongkongyzt Date: Fri, 11 Jan 2019 00:41:41 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=EF=BC=8C=20=E5=AE=8C=E5=96=84pushbear?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UnitTest/TestAll.py | 8 ++++++++ config/pushbearConf.py | 26 ++++++++++++++++++++++++++ config/ticket_config.yaml | 5 +++++ inter/QueryOrderWaitTime.py | 3 +++ tkcode.png | Bin 0 -> 1492 bytes 5 files changed, 42 insertions(+) create mode 100644 tkcode.png diff --git a/UnitTest/TestAll.py b/UnitTest/TestAll.py index 17eb608..3943e70 100644 --- a/UnitTest/TestAll.py +++ b/UnitTest/TestAll.py @@ -6,6 +6,7 @@ import requests from agency.agency_tools import proxy from config.emailConf import sendEmail +from config.pushbearConf import sendPushBear def _set_header_default(): @@ -38,6 +39,13 @@ class testAll(unittest.TestCase): :return: """ sendEmail("订票小助手测试一下") + + def testPushbear(self): + """ + 实测pushbear是否可用 + :return: + """ + sendPushBear("pushbear 微信通知测试一下") # def testConfig(self): # """ diff --git a/config/pushbearConf.py b/config/pushbearConf.py index e69de29..2f3a496 100644 --- a/config/pushbearConf.py +++ b/config/pushbearConf.py @@ -0,0 +1,26 @@ +# -*- coding: utf8 -*- +__author__ = 'kongkongyzt' +import requests +from config.ticketConf import _get_yaml + +PUSH_BEAR_API_PATH = "https://pushbear.ftqq.com/sub" + +def sendPushBear(msg): + """ + pushBear微信通知 + :param str: 通知内容 content + :return: + """ + conf = _get_yaml() + if conf["pushbear_conf"]["is_pushbear"] and conf["pushbear_conf"]["send_key"].strip() != "": + try: + requests.get("{}?sendkey={}&text=来自12306抢票助手的通知&desp={}".format(PUSH_BEAR_API_PATH, conf["pushbear_conf"]["send_key"].strip(), msg)) + print(u"已下发 pushbear 微信通知, 请查收") + except Exception as e: + print(u"pushbear 配置有误 {}".format(e)) + else: + pass + + +if __name__ == '__main__': + sendPushBear(1) \ No newline at end of file diff --git a/config/ticket_config.yaml b/config/ticket_config.yaml index 5738135..80d0509 100755 --- a/config/ticket_config.yaml +++ b/config/ticket_config.yaml @@ -103,6 +103,11 @@ email_conf: password: "" host: "smtp.qq.com" +# 是否开启 pushbear 微信提醒, 使用前需要前往 http://pushbear.ftqq.com 扫码绑定获取 send_key 并关注获得抢票结果通知的公众号 +pushbear_conf: + is_pushbear: False + send_key: "" + # 是否开启cdn查询,可以更快的检测票票 1为开启,2为关闭 is_cdn: 1 diff --git a/inter/QueryOrderWaitTime.py b/inter/QueryOrderWaitTime.py index 9dbc888..2e457ac 100644 --- a/inter/QueryOrderWaitTime.py +++ b/inter/QueryOrderWaitTime.py @@ -4,6 +4,7 @@ import time from config.TicketEnmu import ticket from config.emailConf import sendEmail +from config.pushbearConf import sendPushBear from myException.ticketIsExitsException import ticketIsExitsException from myException.ticketNumOutException import ticketNumOutException @@ -42,6 +43,8 @@ class queryOrderWaitTime: if data and data.get("orderId", ""): sendEmail(ticket.WAIT_ORDER_SUCCESS.format( data.get("orderId", ""))) + sendPushBear(ticket.WAIT_ORDER_SUCCESS.format( + data.get("orderId", ""))) raise ticketIsExitsException(ticket.WAIT_ORDER_SUCCESS.format( data.get("orderId"))) elif data.get("msg", False): diff --git a/tkcode.png b/tkcode.png new file mode 100644 index 0000000000000000000000000000000000000000..35a70ff2c5d30380b1e9b32deaba0d5795f9afd1 GIT binary patch literal 1492 zcmex=Z;0e`ufJk z`uYy2fKia2Ur<<3R7glvL=Xt2M8w2Iq|~IOWTd3j43y=7K-oZBPhDMIPutYgz`)eh z!NDHci2nx|1UVS?F{&~%Dlsq#GBOJ?{y)Ny1#~tuBO}5;K=(2+v#_HIfusc(8JL)u z7@3)vxR@cz8JPr`6@^#~9fbpxL|79G8z*iwa!T5yys$`A5XD50^8dFOc$k4k2r>&Y z*fV^Am@ueF8RO?~I=V}GeC}T>JZfK6FI#!tyerJmv}4}Q{@t&SB=dQnP1`6eo0eU< z#&?mj**5iSwhx!x^7s9?YDd?fV8PdN^Dgi{KYKg6bjH#hoo988Wo~JI3IF*0N9lc$ z?wq%OE*r|{{9A5Ym+{tf&Z{-gE*pyWT>E&g@Qa%6k64qwi`gz8<-b3^AshJo>@uZ| z>o#`Gx%Hzj{dR}%p4-=JE-x$n-dnr*d}h)0_jAtpCEa>FFTLBZc44-AzFv}A+Qog7 zum4W6oKO;e`gU~G?5$t6N5}2??S6GmU2^4hv#x7uR*%%uif5ct7SuYc{rODR{)%x|`ouA2Ji zaLU7(V@@U(P{@blK`9`}}MsD$myWDv+ef|3D7yY$U->;izx9897PewN)gj1FG& z_3ey#>T@jq{SDh!9rQV}%caoRY|kU{FXe|Ajry5u$2Dtij}zEzh+P4-yh z@@<>Cai87BuO_)ax4NC%9Cz>1;d4i#k8k;%yWW0*$ow;A$L`G+mpEtl=08KT@4VQR zyG&hz=fB$e@$J0in+Hv{A2r{aq;}cX?$+n?+xP!5yZ@=?V~$_8=y7?E&I$R;&&}PP z9H%WgqyJgwxB32e*4i8FeSJ%N-Og{@PIUg`vB@p({P--Xa?WwfM@q%VEP{{jagWNm z`7wCOZHu1g+h2CF*Hni0hTY80`kkiycFURKuQNJR|1&Ji`|K0kaX#m^{KIL|)wkV# zT}n^eccm*@Q1bhHkLOd~th*bno_6k{*g7TMO~w}g4ERob($83OO}p-*v7y-WexI^K z(>|NmOt~H#IQzMLY3D$~p(Xv0Y&uHE3to4U0jwF{ZD*Up2f%W5( z^OLQrK8n1({q5mqiMjQiGtU3Ea!VF|IrDoCJhyTfOc3mt%*iMr#AML7@k<0t!XXDY imWCdeUo-mSOBxy#6u|suPDUmNCkME;!NZXMe-i+XX$A)X literal 0 HcmV?d00001 From 3da74df99c8c1548ff90a9a488c19e9253d71c7c Mon Sep 17 00:00:00 2001 From: kongkongyzt Date: Fri, 11 Jan 2019 01:11:18 +0800 Subject: [PATCH 03/12] remove tail whitespace --- config/pushbearConf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/pushbearConf.py b/config/pushbearConf.py index 2f3a496..dd24cc9 100644 --- a/config/pushbearConf.py +++ b/config/pushbearConf.py @@ -3,7 +3,7 @@ __author__ = 'kongkongyzt' import requests from config.ticketConf import _get_yaml -PUSH_BEAR_API_PATH = "https://pushbear.ftqq.com/sub" +PUSH_BEAR_API_PATH = "https://pushbear.ftqq.com/sub" def sendPushBear(msg): """ From 6c78809b4fef4d0fba4fd0a4690c9832cd3a5a49 Mon Sep 17 00:00:00 2001 From: kongkongyzt Date: Fri, 11 Jan 2019 01:14:48 +0800 Subject: [PATCH 04/12] remove tail whitespace --- UnitTest/TestAll.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitTest/TestAll.py b/UnitTest/TestAll.py index 3943e70..8e946fb 100644 --- a/UnitTest/TestAll.py +++ b/UnitTest/TestAll.py @@ -39,7 +39,7 @@ class testAll(unittest.TestCase): :return: """ sendEmail("订票小助手测试一下") - + def testPushbear(self): """ 实测pushbear是否可用 From ced815e7c236d998c469df8f13c615443e51903d Mon Sep 17 00:00:00 2001 From: fbigun Date: Sat, 12 Jan 2019 14:54:22 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E5=A2=9E=E5=8A=A0docker=E5=BF=BD?= =?UTF-8?q?=E7=95=A5=E6=96=87=E4=BB=B6=EF=BC=8C=E5=87=8F=E5=B0=91=E4=B8=8D?= =?UTF-8?q?=E5=BF=85=E8=A6=81=E7=9A=84=E6=96=87=E4=BB=B6=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100755 index 0000000..9e3882d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +**/*.html +**/*.pyc +**/*.yaml +**/*.log +**/*~ +**/.DS_Store +**/Thumbs.db +.idea/ +.git/ From c68cc016e04259d2bba36d96bc74377df071e66e Mon Sep 17 00:00:00 2001 From: wenxianping <931128603@qq.com> Date: Sat, 12 Jan 2019 15:26:02 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BD=99=E7=A5=A8?= =?UTF-8?q?=E4=B8=8D=E8=B6=B3=E4=BC=98=E5=85=88=E6=8F=90=E4=BA=A4=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +- Update.md | 3 + agency/cdn_utils.py | 2 +- config/AutoSynchroTime.py | 14 +- config/urlConf.py | 32 ++-- damatuCode/ruokuai.py | 5 +- init/select_ticket_info.py | 254 ++++++++++++++++---------------- inter/AutoSubmitOrderRequest.py | 5 +- inter/GetPassengerDTOs.py | 17 ++- inter/GetQueueCount.py | 6 +- inter/GetQueueCountAsync.py | 6 +- inter/Query.py | 2 +- inter/SubmitOrderRequest.py | 7 +- 13 files changed, 200 insertions(+), 158 deletions(-) diff --git a/README.md b/README.md index db58ead..0e43309 100755 --- a/README.md +++ b/README.md @@ -79,8 +79,9 @@ - 测试下单接口是否可用,有两个下单接口,随便用哪个都ok - 如果下载验证码过期或者下载失败的问题,应该是12306封ip的策略,多重试几次,12306现在封服务器(阿里云和腾讯云)ip比较严重,尽量不要放在服务器里面 - 感谢一下小伙伴对本项目提供的帮助 - - @ sun7127@126.com - - @才 + - @sun7127@126.com + - @ 才 + - @MonsterTan - 以及所有为此项目提供pr的同学 - [更新日志](Update.md) diff --git a/Update.md b/Update.md index 3cfceb1..9369a5a 100644 --- a/Update.md +++ b/Update.md @@ -134,3 +134,6 @@ - mac和linux服务器自动对点 - 增加预售踩点查询下单,经测试,误差在0.004s +- 2019.01.12更新 + - 增加对python3语法的支持 + - 删除校验时间很多机器不兼容的问题(win10会阻拦对时功能,导致大面积报错),如果是预售,为了不耽误宝贵的时间,请手动对时 diff --git a/agency/cdn_utils.py b/agency/cdn_utils.py index 77698eb..f3c8188 100755 --- a/agency/cdn_utils.py +++ b/agency/cdn_utils.py @@ -76,4 +76,4 @@ class CDNProxy: if __name__ == '__main__': cdn = CDNProxy() - cdn.open_cdn_file() + print(cdn.open_cdn_file()) diff --git a/config/AutoSynchroTime.py b/config/AutoSynchroTime.py index bd8d846..4b41946 100644 --- a/config/AutoSynchroTime.py +++ b/config/AutoSynchroTime.py @@ -15,21 +15,21 @@ def autoSynchroTime(): hosts = ['ntp1.aliyun.com', 'ntp2.aliyun.com', 'ntp3.aliyun.com', 'ntp4.aliyun.com', 'cn.pool.ntp.org'] - print(u"正在同步时间,请耐心等待30秒左右") + print(u"正在同步时间,请耐心等待30秒左右,如果下面有错误发送,可以忽略!!") print(u"系统当前时间{}".format(str(datetime.datetime.now())[:22])) system = platform.system() if system == "Windows": # windows 同步时间未测试过,参考地址:https://www.jianshu.com/p/92ec15da6cc3 for host in hosts: - os.system('w32tm /register') - os.system('net start w32time') - os.system('w32tm /config /manualpeerlist:"{}" /syncfromflags:manual /reliable:yes /update'.format(host)) - os.system('ping -n 3 127.0.0.1 >nul') - sin = os.system('w32tm /resync') + os.popen('w32tm /register') + os.popen('net start w32time') + os.popen('w32tm /config /manualpeerlist:"{}" /syncfromflags:manual /reliable:yes /update'.format(host)) + os.popen('ping -n 3 127.0.0.1 >nul') + sin = os.popen('w32tm /resync') if sin is 0: break else: # mac同步地址,如果ntpdate未安装,brew install ntpdate linux 安装 yum install -y ntpdate for host in hosts: - sin = os.system('ntpdate {}'.format(host)) + sin = os.popen('ntpdate {}'.format(host)) if sin is 0: break print(u"同步后时间:{}".format(str(datetime.datetime.now())[:22])) diff --git a/config/urlConf.py b/config/urlConf.py index 2963815..8365767 100755 --- a/config/urlConf.py +++ b/config/urlConf.py @@ -11,7 +11,7 @@ urls = { "Host": "kyfw.12306.cn", "Content-Type": 1, "re_try": 10, - "re_time": 0.1, + "re_time": 1, "s_time": 0.1, "is_logger": True, "is_json": True, @@ -23,7 +23,7 @@ urls = { "Host": "kyfw.12306.cn", "Content-Type": 1, "re_try": 10, - "re_time": 0.1, + "re_time": 1, "s_time": 0.1, "is_logger": True, "is_json": True, @@ -36,7 +36,7 @@ urls = { "Host": "kyfw.12306.cn", "Content-Type": 1, "re_try": 10, - "re_time": 0.1, + "re_time": 1, "s_time": 0.1, "is_logger": False, "is_json": False, @@ -49,7 +49,7 @@ urls = { "Host": "kyfw.12306.cn", "Content-Type": 1, "re_try": 10, - "re_time": 0.1, + "re_time": 1, "s_time": 0.1, "is_logger": False, "is_json": False, @@ -62,7 +62,7 @@ urls = { "Host": "kyfw.12306.cn", "Content-Type": 1, "re_try": 10, - "re_time": 0.1, + "re_time": 1, "s_time": 0.1, "is_logger": True, "is_json": True, @@ -73,7 +73,7 @@ urls = { "Referer": "https://kyfw.12306.cn/otn/index/init", "Host": "kyfw.12306.cn", "re_try": 1, - "re_time": 0.1, + "re_time": 1, "s_time": 0.1, "is_logger": False, "is_json": False, @@ -84,7 +84,7 @@ urls = { "Referer": "https://kyfw.12306.cn/otn/index/init", "Host": "kyfw.12306.cn", "re_try": 1, - "re_time": 0.1, + "re_time": 1, "s_time": 0.1, "is_logger": False, "is_test_cdn": True, @@ -96,7 +96,7 @@ urls = { "Referer": "https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin", "Host": "kyfw.12306.cn", "re_try": 10, - "re_time": 0.1, + "re_time": 1, "s_time": 0.01, "is_logger": False, "is_json": False, @@ -107,7 +107,7 @@ urls = { "Referer": "https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin", "Host": "kyfw.12306.cn", "re_try": 10, - "re_time": 0.1, + "re_time": 1, "s_time": 0.1, "is_logger": True, "is_json": True, @@ -119,7 +119,7 @@ urls = { "Host": "kyfw.12306.cn", "Content-Type": 1, "re_try": 10, - "re_time": 0.1, + "re_time": 1, "s_time": 0.1, "is_logger": True, "is_json": True, @@ -337,6 +337,18 @@ urls = { "is_logger": True, "is_json": True, }, + "loginAysnSuggest": { # 快速订单排队 + "req_url": "/otn/login/loginAysnSuggest", + "req_type": "post", + "Referer": "https://kyfw.12306.cn/otn/leftTicket/init", + "Content-Type": 1, + "Host": "kyfw.12306.cn", + "re_try": 10, + "re_time": 0.01, + "s_time": 0.1, + "is_logger": True, + "is_json": True, + }, "cdn_host": { "req_url": "http://ping.chinaz.com/kyfw.12306.cn", "req_type": "post" diff --git a/damatuCode/ruokuai.py b/damatuCode/ruokuai.py index 5948790..09509e7 100755 --- a/damatuCode/ruokuai.py +++ b/damatuCode/ruokuai.py @@ -7,7 +7,10 @@ class RClient(object): def __init__(self, username, password): self.username = username - self.password = md5(password).hexdigest() + try: + self.password = md5(password).hexdigest() + except TypeError: + self.password = md5(password.encode('utf-8')).hexdigest() self.soft_id = '96061' self.soft_key = '6facb9da7bb645ad9c4a229464b2cf89' self.base_params = { diff --git a/init/select_ticket_info.py b/init/select_ticket_info.py index f9aa0a3..b8226e9 100755 --- a/init/select_ticket_info.py +++ b/init/select_ticket_info.py @@ -70,7 +70,10 @@ class select: to_station = ticket_info_config["set"]["to_station"] station_dates = ticket_info_config["set"]["station_dates"] set_names = ticket_info_config["set"]["set_type"] - set_type = [seat_conf[x.encode("utf-8")] for x in ticket_info_config["set"]["set_type"]] + try: + set_type = [seat_conf[x.encode("utf-8")] for x in ticket_info_config["set"]["set_type"]] + except KeyError: + set_type = [seat_conf[x] for x in ticket_info_config["set"]["set_type"]] is_more_ticket = ticket_info_config["set"]["is_more_ticket"] ticke_peoples = ticket_info_config["set"]["ticke_peoples"] station_trains = ticket_info_config["set"]["station_trains"] @@ -134,8 +137,12 @@ class select: for i in range(0, len(info)): n_info = info[i].split('|') station_name[n_info[1]] = n_info[2] - from_station = station_name[from_station.encode("utf8")] - to_station = station_name[to_station.encode("utf8")] + try: + from_station = station_name[from_station.encode("utf8")] + to_station = station_name[to_station.encode("utf8")] + except KeyError: + from_station = station_name[from_station] + to_station = station_name[to_station] return from_station, to_station def call_login(self, auth=False): @@ -182,130 +189,127 @@ class select: raise ticketConfigException(u"cdn列表为空,请先加载cdn") def main(self): - autoSynchroTime() # 同步时间 - self.cdn_certification() - l = liftTicketInit(self) - l.reqLiftTicketInit() - self.call_login() - check_user = checkUser(self) - t = threading.Thread(target=check_user.sendCheckUser) - t.setDaemon(True) - t.start() - from_station, to_station = self.station_table(self.from_station, self.to_station) - num = 0 - while 1: - try: - num += 1 - now = datetime.datetime.now() # 感谢群里大佬提供整点代码 - configCommon.checkSleepTime(self) # 晚上到点休眠 - if self.order_model is 1: - sleep_time_s = 0.5 - sleep_time_t = 0.6 - # 测试了一下有微妙级的误差,应该不影响,测试结果:2019-01-02 22:30:00.004555,预售还是会受到前一次刷新的时间影响,暂时没想到好的解决方案 - while not now.strftime("%H:%M:%S") == self.open_time: - now = datetime.datetime.now() - if now.strftime("%H:%M:%S") > self.open_time: - break - time.sleep(0.0001) - else: - sleep_time_s = 0.5 - sleep_time_t = 3 - q = query(session=self, - from_station=from_station, - to_station=to_station, - from_station_h=self.from_station, - to_station_h=self.to_station, - _station_seat=self._station_seat, - station_trains=self.station_trains, - station_dates=self.station_dates, - ticke_peoples_num=len(self.ticke_peoples), - ) - queryResult = q.sendQuery() - # 查询接口 - if queryResult.get("status", False): - train_no = queryResult.get("train_no", "") - train_date = queryResult.get("train_date", "") - stationTrainCode = queryResult.get("stationTrainCode", "") - secretStr = queryResult.get("secretStr", "") - seat = queryResult.get("seat", "") - leftTicket = queryResult.get("leftTicket", "") - query_from_station_name = queryResult.get("query_from_station_name", "") - query_to_station_name = queryResult.get("query_to_station_name", "") - is_more_ticket_num = queryResult.get("is_more_ticket_num", len(self.ticke_peoples)) - if wrapcache.get(train_no): - print(ticket.QUEUE_WARNING_MSG.format(train_no)) + # autoSynchroTime() # 同步时间 + try: + self.cdn_certification() + l = liftTicketInit(self) + l.reqLiftTicketInit() + self.call_login() + check_user = checkUser(self) + t = threading.Thread(target=check_user.sendCheckUser) + t.setDaemon(True) + t.start() + from_station, to_station = self.station_table(self.from_station, self.to_station) + num = 0 + s = getPassengerDTOs(session=self, ticket_peoples=self.ticke_peoples) + s.sendGetPassengerDTOs() + while 1: + num += 1 + now = datetime.datetime.now() # 感谢群里大佬提供整点代码 + configCommon.checkSleepTime(self) # 晚上到点休眠 + if self.order_model is 1: + sleep_time_s = 0.5 + sleep_time_t = 0.6 + # 测试了一下有微妙级的误差,应该不影响,测试结果:2019-01-02 22:30:00.004555,预售还是会受到前一次刷新的时间影响,暂时没想到好的解决方案 + while not now.strftime("%H:%M:%S") == self.open_time: + now = datetime.datetime.now() + if now.strftime("%H:%M:%S") > self.open_time: + break + time.sleep(0.0001) else: - # 获取联系人 - s = getPassengerDTOs(session=self, ticket_peoples=self.ticke_peoples, - set_type=seat_conf_2[seat], - is_more_ticket_num=is_more_ticket_num) - getPassengerDTOsResult = s.getPassengerTicketStrListAndOldPassengerStr() - if getPassengerDTOsResult.get("status", False): - self.passengerTicketStrList = getPassengerDTOsResult.get("passengerTicketStrList", "") - self.oldPassengerStr = getPassengerDTOsResult.get("oldPassengerStr", "") - self.set_type = getPassengerDTOsResult.get("set_type", "") - # 提交订单 - if self.order_type == 1: # 快读下单 - a = autoSubmitOrderRequest(session=self, - secretStr=secretStr, - train_date=train_date, - passengerTicketStr=self.passengerTicketStrList, - oldPassengerStr=self.oldPassengerStr, - train_no=train_no, - stationTrainCode=stationTrainCode, - leftTicket=leftTicket, - set_type=self.set_type, - query_from_station_name=query_from_station_name, - query_to_station_name=query_to_station_name, - ) - a.sendAutoSubmitOrderRequest() - elif self.order_type == 2: # 普通下单 - sor = submitOrderRequest(self, secretStr, from_station, to_station, train_no, self.set_type, - self.passengerTicketStrList, self.oldPassengerStr, train_date, - self.ticke_peoples) - sor.sendSubmitOrderRequest() - else: - random_time = round(random.uniform(sleep_time_s, sleep_time_t), 2) - print(u"正在第{0}次查询 随机停留时长:{6} 乘车日期: {1} 车次:{2} 查询无票 cdn轮询IP:{4}当前cdn总数:{5} 总耗时:{3}ms".format(num, - ",".join( - self.station_dates), - ",".join( - self.station_trains), - ( - datetime.datetime.now() - now).microseconds / 1000, - queryResult.get( - "cdn", - None), - len( - self.cdn_list), - random_time)) - time.sleep(random_time) - except PassengerUserException as e: - print(e) - break - except ticketConfigException as e: - print(e) - break - except ticketIsExitsException as e: - print(e) - break - except ticketNumOutException as e: - print(e) - break - except UserPasswordException as e: - print(e) - break - except ValueError as e: - if e == "No JSON object could be decoded": - print(u"12306接口无响应,正在重试") - else: - print(e) - except KeyError as e: - print(e) - except TypeError as e: - print(u"12306接口无响应,正在重试 {0}".format(e)) - except socket.error as e: + sleep_time_s = 0.5 + sleep_time_t = 3 + q = query(session=self, + from_station=from_station, + to_station=to_station, + from_station_h=self.from_station, + to_station_h=self.to_station, + _station_seat=self._station_seat, + station_trains=self.station_trains, + station_dates=self.station_dates, + ticke_peoples_num=len(self.ticke_peoples), + ) + queryResult = q.sendQuery() + # 查询接口 + if queryResult.get("status", False): + train_no = queryResult.get("train_no", "") + train_date = queryResult.get("train_date", "") + stationTrainCode = queryResult.get("stationTrainCode", "") + secretStr = queryResult.get("secretStr", "") + seat = queryResult.get("seat", "") + leftTicket = queryResult.get("leftTicket", "") + query_from_station_name = queryResult.get("query_from_station_name", "") + query_to_station_name = queryResult.get("query_to_station_name", "") + is_more_ticket_num = queryResult.get("is_more_ticket_num", len(self.ticke_peoples)) + if wrapcache.get(train_no): + print(ticket.QUEUE_WARNING_MSG.format(train_no)) + else: + # 获取联系人 + s = getPassengerDTOs(session=self, ticket_peoples=self.ticke_peoples, + set_type=seat_conf_2[seat], + is_more_ticket_num=is_more_ticket_num) + getPassengerDTOsResult = s.getPassengerTicketStrListAndOldPassengerStr() + if getPassengerDTOsResult.get("status", False): + self.passengerTicketStrList = getPassengerDTOsResult.get("passengerTicketStrList", "") + self.oldPassengerStr = getPassengerDTOsResult.get("oldPassengerStr", "") + self.set_type = getPassengerDTOsResult.get("set_type", "") + # 提交订单 + if self.order_type == 1: # 快读下单 + a = autoSubmitOrderRequest(session=self, + secretStr=secretStr, + train_date=train_date, + passengerTicketStr=self.passengerTicketStrList, + oldPassengerStr=self.oldPassengerStr, + train_no=train_no, + stationTrainCode=stationTrainCode, + leftTicket=leftTicket, + set_type=self.set_type, + query_from_station_name=query_from_station_name, + query_to_station_name=query_to_station_name, + ) + a.sendAutoSubmitOrderRequest() + elif self.order_type == 2: # 普通下单 + sor = submitOrderRequest(self, secretStr, from_station, to_station, train_no, self.set_type, + self.passengerTicketStrList, self.oldPassengerStr, train_date, + self.ticke_peoples) + sor.sendSubmitOrderRequest() + else: + random_time = round(random.uniform(sleep_time_s, sleep_time_t), 2) + print(u"正在第{0}次查询 随机停留时长:{6} 乘车日期: {1} 车次:{2} 查询无票 cdn轮询IP:{4}当前cdn总数:{5} 总耗时:{3}ms".format(num, + ",".join( + self.station_dates), + ",".join( + self.station_trains), + ( + datetime.datetime.now() - now).microseconds / 1000, + queryResult.get( + "cdn", + None), + len( + self.cdn_list), + random_time)) + time.sleep(random_time) + except PassengerUserException as e: + print(e) + except ticketConfigException as e: + print(e) + except ticketIsExitsException as e: + print(e) + except ticketNumOutException as e: + print(e) + except UserPasswordException as e: + print(e) + except ValueError as e: + if e == "No JSON object could be decoded": + print(u"12306接口无响应,正在重试") + else: print(e) + except KeyError as e: + print(e) + except TypeError as e: + print(u"12306接口无响应,正在重试 {0}".format(e)) + except socket.error as e: + print(e) if __name__ == '__main__': diff --git a/inter/AutoSubmitOrderRequest.py b/inter/AutoSubmitOrderRequest.py index 5cc576e..92bdacf 100644 --- a/inter/AutoSubmitOrderRequest.py +++ b/inter/AutoSubmitOrderRequest.py @@ -25,7 +25,10 @@ class autoSubmitOrderRequest: leftTicket, set_type,): self.set_type = set_type - self.secretStr = urllib.unquote(secretStr) + try: + self.secretStr = urllib.unquote(secretStr) + except AttributeError: + self.secretStr = urllib.parse.unquote(secretStr) self.train_date = train_date self.query_from_station_name = query_from_station_name self.query_to_station_name = query_to_station_name diff --git a/inter/GetPassengerDTOs.py b/inter/GetPassengerDTOs.py index ac7573e..82d4f95 100644 --- a/inter/GetPassengerDTOs.py +++ b/inter/GetPassengerDTOs.py @@ -1,4 +1,6 @@ # coding=utf-8 +import json + from config.TicketEnmu import ticket from myException.PassengerUserException import PassengerUserException import wrapcache @@ -14,19 +16,21 @@ class getPassengerDTOs: 获取乘客信息 :return: """ - def __init__(self, session, ticket_peoples, set_type, is_more_ticket_num): + def __init__(self, session, ticket_peoples=None, set_type=None, is_more_ticket_num=None): """ :param session: 登录实例 :param ticket_peoples: 乘客 :param set_type: 坐席 """ + if ticket_peoples is None: + ticket_peoples = [] self.session = session self.ticket_peoples = ticket_peoples self.is_more_ticket_num = is_more_ticket_num - self.set_type = set_type.encode("utf8") + self.set_type = set_type def sendGetPassengerDTOs(self): - getPassengerDTOsResult = self.session.httpClint.send(self.session.urls["get_passengerDTOs"], {}) + getPassengerDTOsResult = self.session.httpClint.send(self.session.urls["get_passengerDTOs"], json.dumps({"_json_att": ""})) if getPassengerDTOsResult.get("data", False) and getPassengerDTOsResult["data"].get("normal_passengers", False): normal_passengers = getPassengerDTOsResult['data']['normal_passengers'] _normal_passenger = [normal_passengers[i] for i in range(len(normal_passengers)) if @@ -38,8 +42,10 @@ class getPassengerDTOs: elif getPassengerDTOsResult.get('messages', False): print(getPassengerDTOsResult.get('messages', False)) else: - print(getPassengerDTOsResult) - raise PassengerUserException(ticket.DTO_NOT_FOUND) + print(u"警告:您的账号可能买票有问题,获取不到联系人,请测试是否能正常下单,在捡漏或者购票!!!") + print(u"警告:您的账号可能买票有问题,获取不到联系人,请测试是否能正常下单,在捡漏或者购票!!!") + print(u"警告:您的账号可能买票有问题,获取不到联系人,请测试是否能正常下单,在捡漏或者购票!!!") + # raise PassengerUserException(ticket.DTO_NOT_FOUND) def getPassengerTicketStr(self, set_type): """ @@ -57,7 +63,6 @@ class getPassengerDTOs: '软座': 2, '软卧': 4, '硬卧': 3, - '动卧': 1, } return str(passengerTicketStr[set_type.replace(' ', '')]) diff --git a/inter/GetQueueCount.py b/inter/GetQueueCount.py index 95d7ada..86d5ed3 100644 --- a/inter/GetQueueCount.py +++ b/inter/GetQueueCount.py @@ -1,5 +1,6 @@ # coding=utf-8 import datetime +import sys import time from collections import OrderedDict import wrapcache @@ -46,7 +47,10 @@ class getQueueCount: :return: """ - new_train_date = filter(None, str(time.asctime(time.strptime(self.station_dates, "%Y-%m-%d"))).split(" ")) + if sys.version_info.major is 2: + new_train_date = filter(None, str(time.asctime(time.strptime(self.station_dates, "%Y-%m-%d"))).split(" ")) + else: + new_train_date = list(filter(None, str(time.asctime(time.strptime(self.station_dates, "%Y-%m-%d"))).split(" "))) data = OrderedDict() data['train_date'] = "{0} {1} 0{2} {3} 00:00:00 GMT+0800 (中国标准时间)".format( new_train_date[0], diff --git a/inter/GetQueueCountAsync.py b/inter/GetQueueCountAsync.py index ab02b24..e7753b2 100644 --- a/inter/GetQueueCountAsync.py +++ b/inter/GetQueueCountAsync.py @@ -1,5 +1,6 @@ # coding=utf-8 import datetime +import sys import time from collections import OrderedDict @@ -56,7 +57,10 @@ class getQueueCountAsync: - _json_att 没啥卵用,还是带上吧 :return: """ - new_train_date = filter(None, str(time.asctime(time.strptime(self.station_dates, "%Y-%m-%d"))).split(" ")) + if sys.version_info.major is 2: + new_train_date = filter(None, str(time.asctime(time.strptime(self.station_dates, "%Y-%m-%d"))).split(" ")) + else: + new_train_date = list(filter(None, str(time.asctime(time.strptime(self.station_dates, "%Y-%m-%d"))).split(" "))) data = OrderedDict() data['train_date'] = "{0} {1} {2} {3} 00:00:00 GMT+0800 (中国标准时间)".format( new_train_date[0], diff --git a/inter/Query.py b/inter/Query.py index ecfeace..436c567 100644 --- a/inter/Query.py +++ b/inter/Query.py @@ -103,7 +103,7 @@ class query: if result: for i in value['result']: ticket_info = i.split('|') - if ticket_info[11] == "Y" and ticket_info[1].encode("utf8") == "预订": # 筛选未在开始时间内的车次 + if ticket_info[11] == "Y" and ticket_info[1] == "预订": # 筛选未在开始时间内的车次 for j in self._station_seat: is_ticket_pass = ticket_info[j] if is_ticket_pass != '' and is_ticket_pass != '无' and is_ticket_pass != '*' and self.check_is_need_train( diff --git a/inter/SubmitOrderRequest.py b/inter/SubmitOrderRequest.py index e5b0623..cb422dc 100644 --- a/inter/SubmitOrderRequest.py +++ b/inter/SubmitOrderRequest.py @@ -19,7 +19,10 @@ class submitOrderRequest: def __init__(self, session, secretStr, from_station, to_station, train_no, set_type, passengerTicketStrList, oldPassengerStr, train_date, ticke_peoples): self.session = session - self.secretStr = secretStr + try: + self.secretStr = urllib.unquote(secretStr) + except AttributeError: + self.secretStr = urllib.parse.unquote(secretStr) self.from_station = from_station self.to_station = to_station self.to_station = to_station @@ -34,7 +37,7 @@ class submitOrderRequest: """ :return: """ - data = [('secretStr', urllib.unquote(self.secretStr)), # 字符串加密 + data = [('secretStr', self.secretStr), # 字符串加密 ('train_date', self.train_date), # 出发时间 ('back_train_date', time()), # 返程时间 ('tour_flag', 'dc'), # 旅途类型 From 271beb01700070e0342fc35588f4492fb881c49a Mon Sep 17 00:00:00 2001 From: wenxianping <931128603@qq.com> Date: Sat, 12 Jan 2019 17:47:37 +0800 Subject: [PATCH 07/12] readme --- README.md | 7 ++++++- init/select_ticket_info.py | 2 +- inter/ConfirmSingleForQueue.py | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0e43309..e439a00 100755 --- a/README.md +++ b/README.md @@ -47,7 +47,12 @@ ![image](https://github.com/testerSunshine/12306/blob/master/uml/uml.png) - 项目声明: - - 本软件只供学习交流使用,务作为商业用途,交流群号:286271084(已满), 2群:649992274(已满),请加3群(未满), 群号:632501142、4群(未满), 群号:606340519 + - 本软件只供学习交流使用,务作为商业用途,交流群号 + - 1群:286271084(已满) + - 2群:649992274(已满) + - 3群:632501142(已满) + - 4群: 606340519(未满) + - 5群: 948526733(未满) - 请不要重复加群,一个群就可以了,把机会留给更多人 - **进群先看公告!!!进群先看公告!!!进群先看公告!!! 重要的事情说三遍** - 能为你抢到一张回家的票,是我最大的心愿 diff --git a/init/select_ticket_info.py b/init/select_ticket_info.py index b8226e9..49f5460 100755 --- a/init/select_ticket_info.py +++ b/init/select_ticket_info.py @@ -96,7 +96,7 @@ class select: print(u"*" * 50) print(u"检查当前python版本为:{},目前版本只支持2.7.10-2.7.15".format(sys.version.split(" ")[0])) - print(u"12306刷票小助手,最后更新于2019.01.08,请勿作为商业用途,交流群号:286271084(已满), 2群:649992274(已满),请加3群(未满), 群号:632501142、4群(未满), 群号:606340519") + print(u"12306刷票小助手,最后更新于2019.01.08,请勿作为商业用途,交流群号:286271084(已满), 2群:649992274(已满),3群:632501142(已满),4群:606340519 (未满),5群:948526733 (未满)") if is_by_time: method_notie = u"购票方式:根据时间区间购票\n可接受最早出发时间:{0}\n可接受最晚抵达时间:{1}\n可接受最长旅途时间:{2}\n可接受列车类型:{3}\n" \ .format(minutes_to_time(departure_time), minutes_to_time(arrival_time), minutes_to_time(take_time), diff --git a/inter/ConfirmSingleForQueue.py b/inter/ConfirmSingleForQueue.py index afa1ac4..d213006 100644 --- a/inter/ConfirmSingleForQueue.py +++ b/inter/ConfirmSingleForQueue.py @@ -79,7 +79,7 @@ class confirmSingleForQueue: if "status" in checkQueueOrderResult and checkQueueOrderResult["status"]: c_data = checkQueueOrderResult["data"] if "data" in checkQueueOrderResult else {} if 'submitStatus' in c_data and c_data['submitStatus'] is True: - print(u"提交订单成功!") + # print(u"提交订单成功!") qow = queryOrderWaitTime(self.session) qow.sendQueryOrderWaitTime() else: From 941cbe6831f2ce6af7fbb19b9411929ef4f4f3d9 Mon Sep 17 00:00:00 2001 From: wenxianping <931128603@qq.com> Date: Sat, 12 Jan 2019 21:28:46 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E6=96=AD=E6=8E=89=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + init/select_ticket_info.py | 236 ++++++++++++++++++------------------- 2 files changed, 119 insertions(+), 118 deletions(-) diff --git a/README.md b/README.md index e439a00..551e828 100755 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ - 测试下单接口是否可用,有两个下单接口,随便用哪个都ok - 如果下载验证码过期或者下载失败的问题,应该是12306封ip的策略,多重试几次,12306现在封服务器(阿里云和腾讯云)ip比较严重,尽量不要放在服务器里面 + - 目前12306对服务器ip比较敏感,大家还是在自己家里挂着吧 - 感谢一下小伙伴对本项目提供的帮助 - @sun7127@126.com - @ 才 diff --git a/init/select_ticket_info.py b/init/select_ticket_info.py index 49f5460..ab5baeb 100755 --- a/init/select_ticket_info.py +++ b/init/select_ticket_info.py @@ -190,126 +190,126 @@ class select: def main(self): # autoSynchroTime() # 同步时间 - try: - self.cdn_certification() - l = liftTicketInit(self) - l.reqLiftTicketInit() - self.call_login() - check_user = checkUser(self) - t = threading.Thread(target=check_user.sendCheckUser) - t.setDaemon(True) - t.start() - from_station, to_station = self.station_table(self.from_station, self.to_station) - num = 0 - s = getPassengerDTOs(session=self, ticket_peoples=self.ticke_peoples) - s.sendGetPassengerDTOs() - while 1: - num += 1 - now = datetime.datetime.now() # 感谢群里大佬提供整点代码 - configCommon.checkSleepTime(self) # 晚上到点休眠 - if self.order_model is 1: - sleep_time_s = 0.5 - sleep_time_t = 0.6 - # 测试了一下有微妙级的误差,应该不影响,测试结果:2019-01-02 22:30:00.004555,预售还是会受到前一次刷新的时间影响,暂时没想到好的解决方案 - while not now.strftime("%H:%M:%S") == self.open_time: - now = datetime.datetime.now() - if now.strftime("%H:%M:%S") > self.open_time: - break - time.sleep(0.0001) + self.cdn_certification() + l = liftTicketInit(self) + l.reqLiftTicketInit() + self.call_login() + check_user = checkUser(self) + t = threading.Thread(target=check_user.sendCheckUser) + t.setDaemon(True) + t.start() + from_station, to_station = self.station_table(self.from_station, self.to_station) + num = 0 + s = getPassengerDTOs(session=self, ticket_peoples=self.ticke_peoples) + s.sendGetPassengerDTOs() + while 1: + try: + num += 1 + now = datetime.datetime.now() # 感谢群里大佬提供整点代码 + configCommon.checkSleepTime(self) # 晚上到点休眠 + if self.order_model is 1: + sleep_time_s = 0.5 + sleep_time_t = 0.6 + # 测试了一下有微妙级的误差,应该不影响,测试结果:2019-01-02 22:30:00.004555,预售还是会受到前一次刷新的时间影响,暂时没想到好的解决方案 + while not now.strftime("%H:%M:%S") == self.open_time: + now = datetime.datetime.now() + if now.strftime("%H:%M:%S") > self.open_time: + break + time.sleep(0.0001) + else: + sleep_time_s = 0.5 + sleep_time_t = 3 + q = query(session=self, + from_station=from_station, + to_station=to_station, + from_station_h=self.from_station, + to_station_h=self.to_station, + _station_seat=self._station_seat, + station_trains=self.station_trains, + station_dates=self.station_dates, + ticke_peoples_num=len(self.ticke_peoples), + ) + queryResult = q.sendQuery() + # 查询接口 + if queryResult.get("status", False): + train_no = queryResult.get("train_no", "") + train_date = queryResult.get("train_date", "") + stationTrainCode = queryResult.get("stationTrainCode", "") + secretStr = queryResult.get("secretStr", "") + seat = queryResult.get("seat", "") + leftTicket = queryResult.get("leftTicket", "") + query_from_station_name = queryResult.get("query_from_station_name", "") + query_to_station_name = queryResult.get("query_to_station_name", "") + is_more_ticket_num = queryResult.get("is_more_ticket_num", len(self.ticke_peoples)) + if wrapcache.get(train_no): + print(ticket.QUEUE_WARNING_MSG.format(train_no)) else: - sleep_time_s = 0.5 - sleep_time_t = 3 - q = query(session=self, - from_station=from_station, - to_station=to_station, - from_station_h=self.from_station, - to_station_h=self.to_station, - _station_seat=self._station_seat, - station_trains=self.station_trains, - station_dates=self.station_dates, - ticke_peoples_num=len(self.ticke_peoples), - ) - queryResult = q.sendQuery() - # 查询接口 - if queryResult.get("status", False): - train_no = queryResult.get("train_no", "") - train_date = queryResult.get("train_date", "") - stationTrainCode = queryResult.get("stationTrainCode", "") - secretStr = queryResult.get("secretStr", "") - seat = queryResult.get("seat", "") - leftTicket = queryResult.get("leftTicket", "") - query_from_station_name = queryResult.get("query_from_station_name", "") - query_to_station_name = queryResult.get("query_to_station_name", "") - is_more_ticket_num = queryResult.get("is_more_ticket_num", len(self.ticke_peoples)) - if wrapcache.get(train_no): - print(ticket.QUEUE_WARNING_MSG.format(train_no)) - else: - # 获取联系人 - s = getPassengerDTOs(session=self, ticket_peoples=self.ticke_peoples, - set_type=seat_conf_2[seat], - is_more_ticket_num=is_more_ticket_num) - getPassengerDTOsResult = s.getPassengerTicketStrListAndOldPassengerStr() - if getPassengerDTOsResult.get("status", False): - self.passengerTicketStrList = getPassengerDTOsResult.get("passengerTicketStrList", "") - self.oldPassengerStr = getPassengerDTOsResult.get("oldPassengerStr", "") - self.set_type = getPassengerDTOsResult.get("set_type", "") - # 提交订单 - if self.order_type == 1: # 快读下单 - a = autoSubmitOrderRequest(session=self, - secretStr=secretStr, - train_date=train_date, - passengerTicketStr=self.passengerTicketStrList, - oldPassengerStr=self.oldPassengerStr, - train_no=train_no, - stationTrainCode=stationTrainCode, - leftTicket=leftTicket, - set_type=self.set_type, - query_from_station_name=query_from_station_name, - query_to_station_name=query_to_station_name, - ) - a.sendAutoSubmitOrderRequest() - elif self.order_type == 2: # 普通下单 - sor = submitOrderRequest(self, secretStr, from_station, to_station, train_no, self.set_type, - self.passengerTicketStrList, self.oldPassengerStr, train_date, - self.ticke_peoples) - sor.sendSubmitOrderRequest() - else: - random_time = round(random.uniform(sleep_time_s, sleep_time_t), 2) - print(u"正在第{0}次查询 随机停留时长:{6} 乘车日期: {1} 车次:{2} 查询无票 cdn轮询IP:{4}当前cdn总数:{5} 总耗时:{3}ms".format(num, - ",".join( - self.station_dates), - ",".join( - self.station_trains), - ( - datetime.datetime.now() - now).microseconds / 1000, - queryResult.get( - "cdn", - None), - len( - self.cdn_list), - random_time)) - time.sleep(random_time) - except PassengerUserException as e: - print(e) - except ticketConfigException as e: - print(e) - except ticketIsExitsException as e: - print(e) - except ticketNumOutException as e: - print(e) - except UserPasswordException as e: - print(e) - except ValueError as e: - if e == "No JSON object could be decoded": - print(u"12306接口无响应,正在重试") - else: + # 获取联系人 + s = getPassengerDTOs(session=self, ticket_peoples=self.ticke_peoples, + set_type=seat_conf_2[seat], + is_more_ticket_num=is_more_ticket_num) + getPassengerDTOsResult = s.getPassengerTicketStrListAndOldPassengerStr() + if getPassengerDTOsResult.get("status", False): + self.passengerTicketStrList = getPassengerDTOsResult.get("passengerTicketStrList", "") + self.oldPassengerStr = getPassengerDTOsResult.get("oldPassengerStr", "") + self.set_type = getPassengerDTOsResult.get("set_type", "") + # 提交订单 + if self.order_type == 1: # 快读下单 + a = autoSubmitOrderRequest(session=self, + secretStr=secretStr, + train_date=train_date, + passengerTicketStr=self.passengerTicketStrList, + oldPassengerStr=self.oldPassengerStr, + train_no=train_no, + stationTrainCode=stationTrainCode, + leftTicket=leftTicket, + set_type=self.set_type, + query_from_station_name=query_from_station_name, + query_to_station_name=query_to_station_name, + ) + a.sendAutoSubmitOrderRequest() + elif self.order_type == 2: # 普通下单 + sor = submitOrderRequest(self, secretStr, from_station, to_station, train_no, self.set_type, + self.passengerTicketStrList, self.oldPassengerStr, train_date, + self.ticke_peoples) + sor.sendSubmitOrderRequest() + else: + random_time = round(random.uniform(sleep_time_s, sleep_time_t), 2) + print(u"正在第{0}次查询 随机停留时长:{6} 乘车日期: {1} 车次:{2} 查询无票 cdn轮询IP:{4}当前cdn总数:{5} 总耗时:{3}ms".format(num, + ",".join( + self.station_dates), + ",".join( + self.station_trains), + ( + datetime.datetime.now() - now).microseconds / 1000, + queryResult.get( + "cdn", + None), + len( + self.cdn_list), + random_time)) + time.sleep(random_time) + except PassengerUserException as e: + print(e) + except ticketConfigException as e: + print(e) + except ticketIsExitsException as e: + print(e) + except ticketNumOutException as e: + print(e) + except UserPasswordException as e: + print(e) + except ValueError as e: + if e == "No JSON object could be decoded": + print(u"12306接口无响应,正在重试") + else: + print(e) + except KeyError as e: + print(e) + except TypeError as e: + print(u"12306接口无响应,正在重试 {0}".format(e)) + except socket.error as e: print(e) - except KeyError as e: - print(e) - except TypeError as e: - print(u"12306接口无响应,正在重试 {0}".format(e)) - except socket.error as e: - print(e) if __name__ == '__main__': From 2f071287a49ea30ff72c446f0d13c6500c01b1d5 Mon Sep 17 00:00:00 2001 From: wenxianping <931128603@qq.com> Date: Mon, 14 Jan 2019 09:46:33 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B7=B2=E7=9F=A5bug?= =?UTF-8?q?=20issues=EF=BC=9Ahttps://github.com/testerSunshine/12306/issue?= =?UTF-8?q?s/177?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ config/configCommon.py | 5 +++-- config/ticket_config.yaml | 25 +++++++++++++------------ init/select_ticket_info.py | 5 +++++ inter/Query.py | 2 +- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 551e828..81b2483 100755 --- a/README.md +++ b/README.md @@ -80,10 +80,12 @@ - 学生票issues [学生票修改](https://github.com/testerSunshine/12306/issues/47) - 依赖安装不对的问题(ImportError)[requirements.txt问题](https://github.com/testerSunshine/12306/issues/91) - 若快豆子疑问 [点我](https://github.com/testerSunshine/12306/issues/67) + - IOError: 【Errno 0】 Error 问题 [点我](https://github.com/testerSunshine/12306/issues/159) - 测试下单接口是否可用,有两个下单接口,随便用哪个都ok - 如果下载验证码过期或者下载失败的问题,应该是12306封ip的策略,多重试几次,12306现在封服务器(阿里云和腾讯云)ip比较严重,尽量不要放在服务器里面 - 目前12306对服务器ip比较敏感,大家还是在自己家里挂着吧 + - 如果想使用此项目的gui版本,请加群,目前只有mac版本 - 感谢一下小伙伴对本项目提供的帮助 - @sun7127@126.com - @ 才 diff --git a/config/configCommon.py b/config/configCommon.py index d02200a..3d7c618 100755 --- a/config/configCommon.py +++ b/config/configCommon.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import datetime import os +import random import sys import time @@ -102,9 +103,9 @@ def getCacheFile(cacheType): def checkSleepTime(session): now = datetime.datetime.now() if now.hour >= 23 or now.hour < 6: - print(u"12306休息时间,本程序自动停止,明天早上七点将自动运行") + print(u"12306休息时间,本程序自动停止,明天早上六点点将自动运行") open_time = datetime.datetime(now.year, now.month, now.day, 6) if open_time < now: open_time += datetime.timedelta(1) - time.sleep((open_time - now).seconds) + time.sleep((open_time - now).seconds + round(random.uniform(1, 10))) session.call_login() diff --git a/config/ticket_config.yaml b/config/ticket_config.yaml index 5738135..ec3ea08 100755 --- a/config/ticket_config.yaml +++ b/config/ticket_config.yaml @@ -5,7 +5,8 @@ set: # - 2018-01-06 # - 2018-01-07 station_dates: - - "2019-02-02" + - "2019-02-10" + - "2019-02-11" # 是否根据时间范围 和 乘车类型 购票 # 否则将需要手动填写车次 @@ -30,15 +31,15 @@ set: # - "G1353" # - "G1329" station_trains: - - "G6172" - - "G6186" - - "G6154" + - "G6153" + - "G6184" + - "G6173" # 出发城市,比如深圳北,就填深圳就搜得到 - from_station: "广州南" + from_station: "邵阳" # 到达城市 比如深圳北,就填深圳就搜得到 - to_station: "邵阳" + to_station: "深圳北" # 座位(list) 多个座位ex: # - "商务座" @@ -54,18 +55,18 @@ set: - "二等座" # 当余票小于乘车人,如果选择优先提交,则删减联系人和余票数一致在提交 - is_more_ticket: True + is_more_ticket: False # 乘车人(list) 多个乘车人ex: # - "张三" # - "李四" ticke_peoples: - - "文贤平" - - "李梦云" -# - "梁敏" + - "" + - "" + # 12306登录账号(list) 12306account: - - user: "13828728396" + - user: "931128603@qq.com" - pwd: "" # 加入小黑屋时间默认为5分钟,此功能为了防止僵尸票导致一直下单不成功错过正常的票, @@ -106,7 +107,7 @@ email_conf: # 是否开启cdn查询,可以更快的检测票票 1为开启,2为关闭 is_cdn: 1 -# 下单接口分为两种,1 为快速下单,2 是普通下单 +# 下单接口分为两种,1 模拟网页自动捡漏下单(不稳定),2 模拟车次后面的购票按钮下单(稳如老狗) order_type: 2 # 下单模式 1 为预售,整点刷新,刷新间隔0.1-0.5S, 然后会校验时间,比如12点的预售,那脚本就会在12.00整检票,刷新订单 diff --git a/init/select_ticket_info.py b/init/select_ticket_info.py index ab5baeb..0698e60 100755 --- a/init/select_ticket_info.py +++ b/init/select_ticket_info.py @@ -291,14 +291,19 @@ class select: time.sleep(random_time) except PassengerUserException as e: print(e) + break except ticketConfigException as e: print(e) + break except ticketIsExitsException as e: print(e) + break except ticketNumOutException as e: print(e) + break except UserPasswordException as e: print(e) + break except ValueError as e: if e == "No JSON object could be decoded": print(u"12306接口无响应,正在重试") diff --git a/inter/Query.py b/inter/Query.py index 436c567..a709427 100644 --- a/inter/Query.py +++ b/inter/Query.py @@ -95,7 +95,7 @@ class query: continue value = station_ticket.get("data", "") if not value: - print (u'{0}-{1} 车次坐席查询为空,ip网络异常,查询url: https://kyfw.12306.cn{2}, 可以手动查询是否有票'.format(self.from_station_h, + print(u'{0}-{1} 车次坐席查询为空,ip网络异常,查询url: https://kyfw.12306.cn{2}, 可以手动查询是否有票'.format(self.from_station_h, self.to_station_h, select_url["req_url"])) else: From c7ca1507325939830c320cd7c25d9f127f69857c Mon Sep 17 00:00:00 2001 From: ferried Date: Mon, 14 Jan 2019 11:27:09 +0800 Subject: [PATCH 10/12] remove settings of Interlij Idea --- .idea/12306.iml | 12 - .idea/inspectionProfiles/Project_Default.xml | 49 - .idea/markdown-exported-files.xml | 8 - .idea/markdown-navigator.xml | 72 -- .../markdown-navigator/profiles_settings.xml | 3 - .idea/misc.xml | 7 - .idea/modules.xml | 8 - .idea/vcs.xml | 6 - .idea/workspace.xml | 1042 ----------------- 9 files changed, 1207 deletions(-) delete mode 100644 .idea/12306.iml delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/markdown-exported-files.xml delete mode 100644 .idea/markdown-navigator.xml delete mode 100644 .idea/markdown-navigator/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml diff --git a/.idea/12306.iml b/.idea/12306.iml deleted file mode 100644 index 3ae6b30..0000000 --- a/.idea/12306.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 36e6057..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/markdown-exported-files.xml b/.idea/markdown-exported-files.xml deleted file mode 100644 index 5d1f129..0000000 --- a/.idea/markdown-exported-files.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/markdown-navigator.xml b/.idea/markdown-navigator.xml deleted file mode 100644 index dbe0e46..0000000 --- a/.idea/markdown-navigator.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml deleted file mode 100644 index 57927c5..0000000 --- a/.idea/markdown-navigator/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 1842d96..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index c883c3a..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 0b34bbf..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,1042 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 12306account - ticket - 联系人不在列表中,请查证后添加 - 飘飘 - select_refresh_interval - 正在尝试排队 - passengerDTOs - 提交订单失败 - ifshowPassCodeTime - 车票提交通过 - query - 出票成功 - 查询到有余票,尝试提交订单 - station_seat - ifShowPassCodeTime - checkOrderInfo - /otn/leftTicket/submitOrderRequest - 文贤平 - 当前余票数小于乘车人数,放弃订票 - 车票提交通过,正在尝试排队 - select_url - loginInit - 验证码提交安全期,等待 - 文贤平(二代身份证-43052419950223777X)存在与本次购票行程冲突的车票!! - logininit - confirmSingleForQueueAsys - is_auto_code - idateM - queryMyOrderNoCompleteUrl - queryMyOrderNoComplete - - - is_auto_code - auto_code_type - self.session.urls - self.session.httpClint - - - - - - - - - - - true - DEFINITION_ORDER - - - - - - - - - - - - - - - - - - - - - - - - - @@ -239,9 +139,7 @@ - - @@ -256,223 +154,12 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + 1535103824843 - - - - - - - - - - - + - + - + @@ -632,32 +316,6 @@ - - - @@ -674,28 +332,12 @@ - - - - + + - - - - - - - - - - - - - - + + @@ -704,18 +346,7 @@ - - - - - - - - - - - - + @@ -731,20 +362,8 @@ - - - - - - - - - - - - - - + + @@ -752,13 +371,7 @@ - - - - - - - + @@ -766,27 +379,9 @@ - - - - - - - - - - - - - - - - - - - - - + + + @@ -811,7 +406,7 @@ - + @@ -834,13 +429,7 @@ - - - - - - - + @@ -865,8 +454,8 @@ - - + + @@ -881,20 +470,8 @@ - - - - - - - - - - - - - - + + @@ -923,41 +500,19 @@ - - - - - - - - - - - - - - + + - - - - - - - - - - - - + + @@ -968,20 +523,7 @@ - - - - - - - - - - - - - - + @@ -1033,8 +575,29 @@ - - + + + + + + + + + + + + + + + + + + + + + + +