Skip to content

Commit

Permalink
cdn
Browse files Browse the repository at this point in the history
  • Loading branch information
testerSunshine committed Jan 29, 2018
1 parent f0fea7c commit 004b828
Show file tree
Hide file tree
Showing 9 changed files with 1,349 additions and 318 deletions.
187 changes: 85 additions & 102 deletions .idea/workspace.xml

Large diffs are not rendered by default.

700 changes: 611 additions & 89 deletions agency/cdn_list

Large diffs are not rendered by default.

24 changes: 20 additions & 4 deletions agency/cdn_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# encoding=utf8
import collections
import datetime
import json
import re
import collections
import sys

import requests

from config import urlConf
import sys
from myUrllib.httpUtils import HTTPClient

reload(sys)
sys.setdefaultencoding('utf-8')

Expand Down Expand Up @@ -92,9 +96,21 @@ def all_cdn(self):
cdn = f.readlines()
return cdn

def cdn_par(self):
with open('./cdn_list', 'r') as f:
cdn = f.readlines()
print cdn
for i in cdn:
http = HTTPClient()
check_user_url = self.urlConf["loginInit"]
http.cdn = i.replace("\n", "")
start_time = datetime.datetime.now()
http.send(check_user_url)
print (datetime.datetime.now() - start_time).microseconds / 1000


if __name__ == '__main__':
cdn = CDNProxy("kyfw.12306.cn")
cdn.get_city_id()
cdn.get_cdn_list()
# print cdn.all_cdn()
# cdn.get_cdn_list()
cdn.cdn_par()
710 changes: 611 additions & 99 deletions cdn_list

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions config/ticket_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ set:
12306count:
# - uesr: ""
# - pwd: "apple1995"
- uesr: "@qq.com"
- uesr: "931128603@qq.com"
- pwd: "QWERTY"

select_refresh_interval: 0.4
Expand All @@ -84,18 +84,18 @@ aotu_code_type: 2
#enable_proxy: False

damatu:
uesr: ""
uesr: "931128603"
pwd: "qazWSX1995"

email_conf:
is_email: True
email: "@qq.com "
email: "931128603@qq.com "
notice_email_list: "[email protected]"
username: ""
username: "931128603"
password: "xwopwxbkupbqbfgb"
host: "smtp.qq.com"

is_cdn: 1
is_cdn: 2



Expand Down
4 changes: 2 additions & 2 deletions config/urlConf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"req_type": "get",
"Referer": "",
"Host": "kyfw.12306.cn",
"re_try": 10,
"re_try": 1,
"re_time": 0.1,
"is_logger": False,
"is_json": False,
Expand Down Expand Up @@ -119,7 +119,7 @@
"req_type": "post",
"Referer": "",
"Host": "kyfw.12306.cn",
"re_try": 10,
"re_try": 1,
"re_time": 0.1,
"is_logger": True,
"is_json": True,
Expand Down
23 changes: 11 additions & 12 deletions init/select_ticket_info.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
# -*- coding=utf-8 -*-
import json
import datetime
import random
import json
import re
import socket
import urllib
import sys
import threading
import time
import urllib
from collections import OrderedDict

from agency.cdn_utils import CDNProxy
from config import urlConf
from init import login
from config.emailConf import sendEmail
from config.ticketConf import _get_yaml
from damatuCode.damatuWeb import DamatuApi
from init import login
from init.login import GoLogin
from myException.PassengerUserException import PassengerUserException
from myException.UserPasswordException import UserPasswordException
from myException.ticketConfigException import ticketConfigException
from myException.ticketIsExitsException import ticketIsExitsException
from myException.ticketNumOutException import ticketNumOutException
from myUrllib.httpUtils import HTTPClient
import threading


reload(sys)
sys.setdefaultencoding('utf-8')
Expand Down Expand Up @@ -648,7 +645,8 @@ def set_cdn(self):
设置cdn
:return:
"""
self.httpClint.cdn = eval(self.cdn_list[random.randint(0, len(self.cdn_list)-1)])["result"].replace("'", "")
# self.httpClint.cdn = eval(self.cdn_list[random.randint(0, len(self.cdn_list)-1)])["result"].replace("'", "")
self.httpClint.cdn = self.cdn_list

def call_login(self, auth=False):
"""
Expand Down Expand Up @@ -689,8 +687,9 @@ def main(self):
self.call_login()
start_time = datetime.datetime.now()
self.submitOrderRequestImplement(from_station, to_station)
print "正在第{0}次查询 乘车日期: {1} 车次{2} 查询无票 cdn查询ip {4} 总耗时{3}ms".format(num, ",".join(self.station_dates), ",".join(self.station_trains), (datetime.datetime.now()-start_time).microseconds/1000, self.httpClint.cdn)
self.set_cdn()
print "正在第{0}次查询 乘车日期: {1} 车次{2} 查询无票 cdn轮询IP {4} 总耗时{3}ms".format(num, ",".join(self.station_dates), ",".join(self.station_trains), (datetime.datetime.now()-start_time).microseconds/1000, self.httpClint.cdn)
if is_cdn == 1:
self.set_cdn()
except PassengerUserException as e:
print e.message
break
Expand All @@ -713,8 +712,8 @@ def main(self):
print(e.message)
except KeyError as e:
print(e.message)
# except TypeError as e:
# print("12306接口无响应,正在重试 {0}".format(e.message))
except TypeError as e:
print("12306接口无响应,正在重试 {0}".format(e.message))
except socket.error as e:
print(e.message)

Expand Down
9 changes: 4 additions & 5 deletions myUrllib/httpUtils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# -*- coding: utf8 -*-
import datetime
import json
import socket
from time import sleep

import requests
import sys

from config import logger

Expand Down Expand Up @@ -102,22 +100,23 @@ def send(self, urls, data=None, **kwargs):
if is_logger:
logger.log(
u"url: {0}\n入参: {1}\n请求方式: {2}\n".format(urls["req_url"],data,method,))
self.setHeadersHost(urls["Host"])
if self.cdn:
self.setHeadersHost(urls["Host"])
url_host = self.cdn
else:
self.setHeadersHost("")
url_host = urls["Host"]
for i in range(urls["re_try"]):
try:
print("https://" + url_host + urls["req_url"])
requests.packages.urllib3.disable_warnings()
response = self._s.request(method=method,
timeout=10,
timeout=2,
url="https://" + url_host + urls["req_url"],
data=data,
allow_redirects=allow_redirects,
verify=False,
**kwargs)
print(response.status_code)
if response.status_code == 200:
if response.content:
if is_logger:
Expand Down
Binary file modified tkcode
Binary file not shown.

0 comments on commit 004b828

Please sign in to comment.