diff --git a/agency/cdn_utils.py b/agency/cdn_utils.py index 9909797cf6553c033391a3fecb5c28ce09005ca8..b4d2238d93c74d945103e38a8286d7d55fed509d 100644 --- a/agency/cdn_utils.py +++ b/agency/cdn_utils.py @@ -1,15 +1,11 @@ # encoding=utf8 import collections -import datetime import json import re import sys - +import csv import requests - from config import urlConf -from myUrllib.httpUtils import HTTPClient - reload(sys) sys.setdefaultencoding('utf-8') @@ -88,7 +84,7 @@ class CDNProxy: num += 1 except Exception as e: print(e.message) - print("本次cdn获取完成,总个数{0}".format(num)) + print(u"本次cdn获取完成,总个数{0}".format(num)) def all_cdn(self): """获取cdn列表""" @@ -96,21 +92,17 @@ class CDNProxy: 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 + def par_csv(self): + cdn_csv = csv.reader(open("../cdn1.csv", "r")) + for c in cdn_csv: + cdn_re = re.compile(r'https://(\S+)/otn/index/init') + cdn_ip = re.findall(cdn_re, c[0]) + if cdn_ip and c[2] == "200": + print(cdn_ip[0]) if __name__ == '__main__': - cdn = CDNProxy("kyfw.12306.cn") + cdn = CDNProxy() cdn.get_city_id() # cdn.get_cdn_list() - cdn.cdn_par() + cdn.par_csv() diff --git a/cdn_list b/cdn_list index 06804c9d4c0eac1cb4bc6a48a31481eadec3b7dd..384dc72f9b8c46ee0a0b76105d718fdffacdf14e 100644 --- a/cdn_list +++ b/cdn_list @@ -1,611 +1,915 @@ -150.138.169.233 +121.14.117.148 +183.62.114.157 +183.61.26.197 +103.254.188.216 +183.62.114.247 +14.18.201.47 +14.18.17.241 +112.65.220.226 +210.38.3.42 +121.14.117.134 +159.226.225.139 +42.81.9.47 +14.18.17.249 +218.242.102.151 +111.206.186.37 +157.255.68.113 +101.227.176.34 +111.206.186.42 +101.227.102.18 +183.232.189.31 +218.78.185.210 +58.63.233.35 +14.18.201.37 +59.81.64.174 +58.63.233.24 +58.63.233.30 +101.227.176.34 +183.232.189.41 +14.18.201.48 +116.199.127.37 +116.199.127.56 +157.255.68.114 +14.18.201.36 +14.18.201.34 +111.206.193.209 +14.18.201.35 +14.18.201.28 +101.227.175.218 +101.227.176.34 +125.90.206.144 +125.90.206.182 +43.243.234.235 +101.227.97.163 +125.89.198.81 +14.119.124.101 +14.21.78.136 +61.149.9.136 +60.207.246.98 +125.90.206.143 +111.202.83.137 +60.207.246.15 +58.220.71.69 +111.206.186.41 +111.13.135.248 +111.178.233.87 +42.81.10.94 +218.242.102.138 +113.107.58.182 +61.156.243.247 +183.58.18.36 +175.43.20.81 +112.90.135.238 +125.90.204.32 +113.107.44.166 +112.91.129.184 +122.70.142.141 +218.205.75.37 +61.149.9.224 +116.199.127.55 +183.131.168.154 +114.80.143.105 183.131.192.83 -117.27.241.176 -115.231.22.33 -115.231.84.169 -115.231.22.80 -58.216.21.23 -123.138.60.143 -117.27.245.89 -61.188.191.26 -61.188.191.84 -175.43.124.142 -60.222.221.62 -222.243.110.146 -222.243.110.149 -117.21.168.87 -182.132.33.24 -182.132.33.26 -112.25.35.53 -61.188.191.30 -220.162.97.245 -61.90.241.26 -61.188.191.215 -220.162.97.241 -222.245.77.22 -222.163.201.28 -113.5.80.100 -182.140.147.63 -182.132.33.22 -221.229.167.32 -61.188.191.20 -220.165.142.37 -218.58.222.19 -211.142.22.26 -113.207.72.19 -220.194.200.180 -60.174.241.25 -61.188.191.27 -220.162.97.243 -61.54.219.34 -113.5.80.93 -114.80.143.144 -120.192.199.13 -175.43.20.60 +101.227.176.34 +116.224.87.45 +116.224.86.30 +183.236.10.216 +183.131.210.66 +183.134.12.69 +101.227.175.215 +14.18.201.26 +112.90.213.65 +42.81.9.23 +42.81.10.88 +101.227.175.216 +58.220.71.71 +125.90.204.122 +219.138.21.110 +183.131.168.145 +117.144.227.9 +113.107.44.234 +117.27.241.90 +101.227.176.34 +115.231.22.125 +125.77.130.208 +222.186.145.188 +14.119.124.100 +122.225.28.145 +101.227.175.207 +112.90.135.61 +122.70.142.142 +58.63.233.29 +211.68.71.214 +36.250.87.94 +116.224.86.29 +211.68.71.215 +101.227.98.134 +183.236.28.147 +122.226.47.123 +101.227.176.34 +43.243.234.20 +116.224.87.29 +58.220.71.107 +58.216.109.186 +58.222.42.9 +58.220.72.205 +183.131.168.24 +60.210.18.222 +112.240.60.226 +58.51.241.34 +183.236.10.215 +122.225.28.79 +183.134.12.70 +60.28.100.38 +115.231.20.119 +115.231.74.76 121.18.230.86 -59.56.26.36 -182.140.147.58 -61.54.219.8 +183.134.9.59 +36.25.241.152 +183.131.168.23 +42.48.110.26 +183.236.28.144 +125.90.204.33 +58.253.193.135 +113.107.57.43 +42.81.9.22 +60.28.100.26 +124.236.97.222 +111.161.22.27 182.140.147.106 -122.70.142.160 -120.192.199.26 -219.243.47.166 -162.105.28.232 -120.192.199.12 -120.192.199.4 -120.192.199.13 -120.192.199.3 -115.231.82.101 -106.3.62.198 -115.231.82.59 -115.231.82.62 -115.231.82.58 -115.231.82.60 -112.253.19.162 -112.253.19.161 -122.70.142.142 -122.70.142.144 -175.43.124.143 -112.253.19.159 -175.43.124.145 -122.70.142.145 -175.43.124.146 -101.227.66.152 -121.18.230.43 -121.18.230.42 -121.18.230.44 -121.18.230.45 -122.70.142.143 -222.243.110.147 -222.243.110.149 -222.243.110.146 -222.243.110.148 -110.18.244.138 -110.18.244.140 -110.18.244.141 -112.253.19.163 -115.231.84.62 -115.231.84.64 -218.60.106.91 -61.188.191.27 -175.43.124.141 -61.188.191.26 -61.188.191.28 -115.156.188.138 -112.253.19.164 +122.225.28.75 +183.134.11.90 +61.155.237.22 +101.227.176.34 +116.224.86.30 +125.90.205.2 +221.179.172.203 +112.90.212.126 +42.245.252.136 +125.90.204.52 +183.232.189.180 +125.90.206.223 +183.134.9.58 +59.56.26.49 +221.206.120.101 +58.223.166.231 +43.226.162.32 +125.77.130.216 +163.177.243.251 +111.206.239.24 +122.225.28.83 +113.96.161.100 +222.245.77.74 +120.221.66.243 +42.81.28.75 +58.51.241.28 +222.246.212.91 +125.90.204.54 +180.97.217.77 +183.134.14.143 +61.155.237.56 +183.134.10.85 +183.131.168.20 +122.226.47.106 +58.220.72.206 +113.107.57.214 +60.174.243.166 +101.227.176.34 +183.131.210.66 +183.236.28.143 +111.206.186.245 +120.241.66.116 +122.226.47.105 +122.225.28.80 +183.61.26.225 +183.134.53.224 +14.215.228.48 +221.179.172.206 +42.81.28.99 +101.70.152.37 +112.90.246.87 +61.167.54.109 +115.231.20.38 +60.5.255.222 +117.144.227.14 +61.147.227.244 +113.107.46.84 +14.119.124.41 +111.161.120.54 +202.75.220.124 +111.206.186.50 +222.245.77.19 +101.227.176.34 +122.225.28.80 +218.92.220.16 +223.151.245.16 +116.224.86.46 +61.184.116.79 +43.226.162.20 +101.71.32.162 +101.227.176.34 +202.75.220.124 +115.231.20.37 +111.161.120.50 +153.99.235.197 +113.107.44.245 +123.183.164.136 +111.6.184.9 +101.227.102.199 +42.81.28.74 +117.23.6.81 +183.57.28.61 +111.6.184.243 +221.202.204.253 +101.227.176.34 +117.144.227.14 +221.179.172.205 +101.227.175.42 +113.16.209.171 +111.206.239.19 +42.81.28.114 +115.231.20.39 +58.51.168.196 +61.147.211.20 +14.21.78.135 +125.90.47.177 +101.71.32.157 +124.236.97.221 +111.161.22.15 +115.231.20.40 +112.17.2.110 +58.222.19.61 +111.206.239.35 +111.206.239.44 +101.227.176.34 +101.71.32.157 +223.151.245.45 106.3.62.194 -220.165.142.37 -220.165.142.38 -220.165.142.35 -220.165.142.39 -220.165.142.40 -219.146.68.84 -219.146.68.78 -219.146.68.79 -61.138.219.8 -61.138.219.7 -182.132.33.24 -182.132.33.22 -182.132.33.21 -182.132.33.23 -61.138.219.10 -61.138.219.6 -58.216.21.23 -220.165.142.36 -58.216.21.24 +125.90.206.136 +183.214.132.122 +117.23.2.85 +60.220.194.210 +111.161.22.17 +111.206.239.53 +122.225.28.146 +122.228.22.248 +183.131.208.60 +221.179.172.238 +111.161.120.199 +221.233.145.198 +153.99.235.198 +113.16.210.132 +122.70.142.39 +59.56.30.221 +101.66.224.145 +14.215.100.72 +111.161.120.63 +220.194.203.66 +125.39.1.138 +116.207.132.219 +101.227.176.34 +101.227.176.34 +183.134.12.69 +101.227.176.34 +183.131.208.60 +101.227.176.34 +183.134.53.224 +101.227.176.34 +122.225.28.146 +101.227.176.34 +183.131.168.20 +101.227.176.34 +122.225.28.83 +101.227.176.34 +122.225.28.79 +183.214.133.48 +36.99.32.179 +111.6.185.245 +101.227.102.176 +101.71.32.153 +42.81.28.118 +218.75.225.192 +61.147.211.40 +115.231.20.108 +101.227.102.175 +115.231.20.115 +58.222.19.49 +59.63.234.87 +180.97.178.170 +222.245.78.6 +101.227.102.173 +221.235.187.132 +60.210.23.47 +111.178.233.88 +115.231.171.14 +101.227.176.34 +180.97.178.170 +59.63.244.94 +222.245.77.75 +110.18.244.63 +117.149.145.87 +115.231.171.13 +58.51.168.194 +221.180.209.125 +59.63.227.214 58.216.21.25 -61.138.219.9 -58.216.21.22 -60.174.241.31 -211.142.22.26 -60.174.241.29 -60.174.241.30 -115.156.188.137 -123.138.60.143 -222.243.110.150 -115.231.84.65 -123.138.60.145 -123.138.60.144 -211.142.22.24 -61.54.219.39 -61.54.219.75 -61.54.219.38 -119.84.111.83 -175.43.20.56 -202.122.145.86 -175.43.20.58 -175.43.20.57 -211.142.22.25 -101.227.66.151 -112.25.35.52 -112.25.35.53 -112.25.35.54 -202.122.145.214 -112.25.35.56 -112.25.35.55 -119.84.111.44 -119.84.111.45 -119.84.111.47 -175.43.20.60 -61.54.219.43 -60.174.241.28 -175.43.124.144 -121.18.230.46 -121.18.230.47 -114.80.143.158 -182.140.147.59 -182.140.147.62 -182.140.147.79 -182.140.147.76 -182.140.147.77 -180.180.248.185 -182.140.147.78 -182.140.147.61 -182.140.147.58 -123.138.60.146 -111.161.22.27 -101.227.66.150 -175.154.189.30 -221.229.167.47 -36.250.74.83 -115.231.22.80 -113.200.235.30 -119.84.111.43 -119.84.111.41 -119.84.111.42 -116.55.236.36 -115.231.171.17 +211.91.168.40 +101.227.176.34 115.231.171.13 -116.55.236.38 +59.56.30.194 +115.231.171.17 +183.66.109.245 115.231.171.16 +42.81.28.117 +218.60.51.254 +180.97.180.45 +58.216.21.22 +124.239.186.165 +101.227.176.34 +115.231.171.16 +183.131.124.101 +113.16.212.189 +115.231.74.154 +58.220.39.92 +112.17.2.18 +119.6.226.144 +43.226.162.63 +61.155.237.48 +182.140.218.64 +211.91.168.24 +222.245.77.21 +153.101.56.251 +125.90.204.42 +111.161.120.65 +113.16.208.101 +222.243.141.100 +121.22.252.52 +61.54.84.212 +221.235.187.129 +222.243.141.95 +111.161.22.16 +61.184.117.52 +124.225.163.31 +119.6.226.157 +61.184.117.30 +211.142.197.57 +222.243.141.98 +61.184.116.78 +101.227.176.34 +58.220.39.92 +123.138.157.109 +218.60.51.253 +222.180.166.229 +111.161.122.176 +111.206.239.49 +116.211.79.26 +58.216.21.253 +116.211.79.27 +111.47.221.223 +211.91.168.35 +123.138.128.106 +101.227.102.185 +221.235.187.134 +221.235.187.133 +115.231.171.18 +211.91.168.33 +211.91.168.31 +220.202.77.119 +101.227.176.34 115.231.171.14 -220.165.142.51 -116.55.236.37 -116.55.236.45 -221.235.187.76 -220.162.97.245 -220.162.97.209 -220.162.97.241 -220.162.97.246 -115.231.84.169 -116.55.236.39 -117.27.245.62 +27.148.151.214 +111.47.221.244 +211.91.168.34 +101.227.176.34 +183.131.124.101 +101.227.176.34 +122.226.47.106 +101.227.176.34 +122.226.47.105 +101.227.176.34 +58.216.21.253 +61.147.210.175 +218.58.206.55 +58.221.78.39 +61.149.22.99 +111.202.83.253 +60.28.100.165 +218.77.92.243 +60.210.23.112 +118.180.15.113 +180.97.244.192 +182.140.130.25 +115.231.20.49 +111.47.220.214 +125.77.134.79 +222.218.87.131 +111.47.219.83 +218.29.49.71 +101.227.98.24 +171.90.249.191 +101.227.176.34 +122.228.233.208 +111.62.244.178 +36.248.5.36 +117.27.243.113 +58.216.109.187 +58.220.71.109 +101.227.176.34 +58.216.109.187 +58.223.166.227 +182.106.194.107 +58.222.42.59 +180.97.244.205 +58.50.31.33 +221.229.202.149 +115.231.22.80 +125.46.22.125 +60.217.22.146 +180.97.244.193 +101.227.176.34 +115.231.171.17 +59.49.42.253 +218.60.51.46 202.118.10.115 -118.180.15.110 -61.188.191.20 -61.188.191.22 -61.188.191.21 -61.167.54.239 -61.188.191.19 -61.167.54.238 -61.167.54.237 -61.167.54.236 -61.167.54.109 -111.26.136.223 -119.84.111.38 -113.207.72.17 -123.138.60.147 -113.207.72.20 -113.207.72.19 -202.118.10.117 -111.161.22.17 -111.161.22.16 -110.18.244.142 -59.56.26.49 -59.56.26.35 -59.56.26.36 -59.56.26.37 -118.180.15.74 -118.180.15.73 -118.180.15.69 -118.180.15.71 -110.18.244.137 -118.180.15.72 -59.56.26.34 -112.253.19.160 -113.200.235.18 -113.200.235.17 -118.180.15.94 -113.200.235.15 -36.250.87.94 -113.200.235.16 -59.56.26.33 -183.136.217.73 -183.136.217.75 -60.207.246.98 -117.27.245.89 -113.207.72.67 -113.207.69.72 -220.162.97.243 -183.136.217.74 -117.27.245.87 -117.27.245.85 -220.162.97.242 -112.90.246.87 -61.90.241.26 -117.27.245.88 -183.250.179.36 -61.167.54.108 -210.66.46.19 -115.231.171.15 -182.140.147.81 -183.250.179.23 -183.250.179.24 -183.250.179.12 -183.250.179.25 -221.235.187.132 -183.250.179.11 -36.250.87.26 -175.43.20.81 -60.222.221.65 -60.222.221.62 -60.222.221.61 -36.250.87.30 +124.239.147.112 +218.92.220.17 +103.254.191.185 +182.140.236.57 +222.211.64.91 +101.227.176.34 +218.92.220.17 +222.20.147.174 +101.66.224.100 +183.66.109.244 +58.218.208.199 +60.174.241.88 +222.55.12.67 +117.144.227.49 +36.25.241.156 +122.70.142.34 +218.21.175.198 +150.138.169.233 36.250.87.27 +202.118.10.117 +106.3.62.212 +101.66.224.112 +111.6.177.209 +58.222.19.45 +14.215.100.48 +36.99.32.182 +219.138.21.63 +111.41.54.182 +36.102.235.206 +218.12.228.96 +222.89.68.50 +125.77.130.215 +36.99.32.181 +101.227.176.34 +101.66.224.100 +113.16.212.192 +111.62.240.181 +59.56.26.18 +182.106.194.110 +113.207.77.191 +59.44.30.114 +101.66.224.148 +218.205.75.186 +42.243.147.114 +139.215.210.38 +218.12.228.93 +110.18.244.76 +110.157.233.40 +218.77.2.32 +111.6.178.48 +218.12.228.95 +211.142.22.114 +60.210.23.110 +150.138.111.197 +112.51.125.201 +115.153.176.103 +183.66.109.243 +118.118.216.115 +116.207.132.220 +219.147.93.222 +222.211.64.87 +113.6.229.176 +101.227.176.34 +218.205.75.186 +125.64.102.187 +60.207.246.16 +180.97.180.150 +125.44.96.186 +139.215.210.58 +59.63.80.114 +117.161.5.207 +123.138.60.144 +125.77.130.207 +101.227.176.34 +59.81.64.174 +58.216.21.10 +49.79.232.225 +218.12.228.94 +58.216.21.23 +218.7.220.37 +180.97.178.198 +123.183.164.123 +117.21.168.19 +112.29.203.246 +218.12.228.87 +202.114.91.28 +124.239.186.159 +60.213.132.71 +113.207.70.205 +123.128.14.202 +221.180.192.143 +111.19.136.240 +59.47.226.254 +60.210.23.125 +112.240.60.46 +42.245.233.188 +218.98.27.64 +60.174.241.125 +183.66.109.3 +219.148.174.55 +122.226.47.55 +124.165.216.254 +36.250.74.100 +115.231.22.102 +59.49.42.252 +125.90.204.44 +49.79.232.224 +121.251.255.236 +221.230.143.101 +122.228.233.206 +111.8.9.196 +219.148.174.21 +221.235.187.24 +218.64.94.40 +59.80.22.192 +218.92.220.15 +110.18.244.14 +106.122.250.172 +101.227.176.34 +122.226.47.55 +183.131.208.50 +182.140.236.58 +101.227.176.34 +183.131.208.50 +111.62.244.177 +182.140.147.76 +113.16.208.70 +211.91.168.22 +124.225.162.68 +183.236.28.148 +112.51.121.164 +101.69.104.73 +43.226.162.39 +221.235.187.63 +202.171.255.153 +118.212.138.52 +219.155.204.39 +60.211.208.49 +115.231.22.29 +111.206.239.48 +218.92.220.55 +36.25.241.162 +115.231.22.33 +110.157.232.182 113.107.112.214 -113.107.112.168 +222.243.141.94 +118.212.138.132 +218.92.209.74 +123.53.139.202 113.107.112.167 -218.92.220.15 -61.188.191.30 -218.92.220.17 +112.90.212.116 +112.90.209.4 +211.91.168.30 +125.39.1.130 +221.230.141.78 +36.104.132.156 +222.246.212.24 +218.92.227.121 +202.171.255.156 +58.216.109.107 +111.161.120.59 +122.70.142.23 +113.107.58.17 +111.178.233.29 +101.227.176.34 +115.231.22.33 +36.250.87.29 +119.188.130.22 +218.76.94.172 +113.107.58.20 +58.216.110.2 +218.60.132.31 +121.31.28.101 +115.153.176.78 +117.23.51.105 +106.122.250.198 +112.90.212.115 +221.230.143.102 +101.227.176.34 +58.216.109.107 +115.231.22.34 +124.236.97.228 +117.187.46.241 +120.221.66.242 +36.25.241.161 +180.97.180.16 +61.184.117.53 +211.142.194.88 +58.216.23.119 +110.157.235.63 +112.90.212.114 +112.90.135.99 +211.142.194.163 +119.188.130.20 +58.216.21.24 221.229.167.32 -61.188.191.29 -221.229.167.31 -221.229.167.36 -60.222.221.66 -125.90.204.34 -125.90.204.33 -58.222.19.59 -61.188.191.85 -125.90.204.32 -58.222.19.51 -58.222.19.52 -58.222.19.54 -61.188.191.215 -58.222.19.53 +211.91.168.39 +115.231.22.31 +125.77.130.209 +112.51.125.202 +61.147.210.34 +101.66.224.115 +183.214.132.121 +61.136.165.32 +222.245.77.51 +175.43.124.141 +61.155.237.50 +220.194.203.75 +220.194.200.180 +61.147.227.140 +61.184.116.33 182.140.147.80 -61.188.191.217 -61.188.191.216 +113.16.212.193 +60.222.221.62 +211.142.194.67 +123.138.157.81 +222.243.141.96 +115.153.176.39 +58.222.19.72 +101.227.176.34 +101.66.224.115 +122.228.233.209 +125.39.1.128 +36.25.241.153 +59.56.30.206 +59.56.26.33 +113.207.70.204 +59.49.94.147 +58.221.78.14 +58.223.166.188 +113.207.4.115 +125.46.22.32 +111.20.250.62 +36.102.230.28 +110.53.75.44 +150.138.168.115 +101.100.190.112 +61.54.121.45 +124.167.232.125 +219.147.92.64 +218.87.111.64 +101.227.176.34 +122.228.233.209 +60.9.1.129 +122.143.27.169 +221.180.192.149 +116.211.79.25 +122.70.142.30 +36.250.74.83 +125.75.34.27 +219.147.233.232 +123.138.60.232 +150.138.214.83 +113.142.80.173 +222.186.141.186 +122.136.46.107 +101.69.146.229 +110.18.244.137 +124.164.8.65 +60.210.23.42 +124.116.133.97 +118.212.148.145 +183.131.208.85 +117.145.179.175 +125.75.32.252 +113.207.71.12 +42.123.108.8 +182.140.147.62 +221.203.4.70 +101.227.176.34 +222.186.141.186 +106.122.250.162 +42.123.117.99 +14.215.100.59 +36.104.131.6 +58.216.21.43 +125.90.204.43 +123.161.57.38 +218.92.227.85 +182.140.236.17 +220.194.200.179 +222.138.255.50 +182.140.130.15 +220.194.200.178 +125.42.203.176 +61.147.227.246 +36.250.87.26 +221.229.167.31 +27.155.72.241 +59.56.26.100 +61.157.122.58 +122.228.233.15 +218.12.228.92 +121.18.230.46 +112.90.246.108 +117.21.168.87 +42.123.107.43 +124.239.186.154 +123.128.14.223 +111.6.176.115 +36.104.131.8 +123.53.139.232 +111.47.221.228 +119.6.226.148 58.222.19.50 -222.163.201.24 -222.163.201.29 -113.107.112.164 -182.140.147.104 -113.207.69.18 -113.207.69.16 -222.163.201.27 -222.163.201.30 -125.90.204.31 -222.23.55.208 -222.245.77.19 -222.245.77.21 -121.18.230.86 -182.132.33.26 -58.216.21.21 -61.188.191.84 -222.245.77.22 -218.92.220.55 -182.132.33.25 -222.245.77.17 -61.174.63.232 -60.222.221.59 +42.56.80.122 +61.163.111.75 +61.54.7.193 +101.100.190.104 +113.207.4.66 +115.153.176.66 +101.227.176.34 +101.227.102.182 +58.216.21.43 +58.221.78.105 +117.145.179.85 +219.148.174.43 +106.3.62.213 +113.207.79.197 +219.148.174.54 +61.54.84.99 +59.44.25.59 221.235.187.64 +182.140.218.63 +219.144.78.197 +60.13.41.74 +117.23.51.76 +101.69.104.74 +121.31.23.53 +117.23.51.77 +113.16.210.131 +106.122.250.194 +14.215.231.134 +60.5.254.21 +125.39.1.129 +106.122.252.2 +111.20.250.25 +211.97.73.244 +125.44.96.185 +60.5.254.42 +60.222.221.66 +27.148.151.187 +112.51.125.198 +122.228.22.247 +175.43.124.144 +121.18.230.42 +125.46.22.126 +221.235.187.62 +218.76.105.86 +112.84.104.48 +211.142.194.69 +61.167.54.238 +222.89.68.32 +122.228.233.182 +101.227.176.34 58.221.78.105 -61.138.219.85 -218.58.222.99 -113.5.80.100 -218.58.222.19 -113.5.80.90 -61.167.54.240 -180.97.180.44 -113.5.80.93 -61.174.63.203 -61.174.63.205 -61.174.63.200 -61.174.63.204 -180.97.180.47 -60.223.235.139 -180.97.180.45 -180.97.180.46 -113.5.80.91 +219.148.174.23 +14.204.74.92 +124.163.204.105 +221.229.203.218 +110.18.244.140 +59.56.26.17 +61.188.191.85 +117.27.245.87 +150.138.214.84 +60.174.241.22 +111.8.9.204 +180.97.244.206 +112.90.212.38 +125.46.22.29 +58.221.78.91 +110.18.244.141 +123.138.60.145 +221.204.31.100 +122.138.54.177 +182.140.147.61 +111.20.250.26 +223.111.130.121 +60.174.241.23 60.223.235.142 -118.180.15.113 -175.43.124.195 -220.194.200.177 -220.194.200.179 -220.194.200.180 -42.81.5.76 -42.81.5.79 -61.156.243.247 -222.186.17.100 -60.174.241.88 -182.34.127.94 -220.194.200.178 -218.29.50.48 -113.5.80.125 -218.76.105.75 -218.60.109.74 -182.140.236.27 -122.143.27.169 -211.162.39.113 -61.138.219.87 -115.231.22.33 -121.192.176.198 -115.231.22.31 -115.231.22.34 -115.231.22.32 -58.216.21.93 -125.90.204.122 -180.97.178.210 -117.27.245.75 -122.136.46.107 -222.163.201.28 +211.142.194.28 +60.255.143.124 +36.33.158.48 +27.148.151.17 +119.36.82.248 +125.77.130.214 +113.207.77.192 +61.156.243.234 +222.211.64.51 +101.227.176.34 +180.97.180.16 +61.136.167.72 +218.92.221.212 +111.6.192.131 +58.216.21.21 +101.227.176.34 +61.156.243.233 +221.229.167.32 +27.148.151.213 +60.217.22.143 +58.221.78.17 +211.97.76.170 +121.18.230.43 +60.5.254.39 +61.132.238.115 220.194.200.232 -61.54.219.34 -119.84.111.46 -116.211.79.31 -58.222.19.61 -222.243.110.164 -117.27.241.176 -222.132.5.100 -121.192.176.196 -175.43.124.142 -115.231.84.61 -61.188.191.218 -112.65.220.39 -218.58.222.20 +111.23.11.52 +121.18.168.68 +211.142.22.81 +117.27.245.88 +218.26.75.207 +101.227.176.34 +58.221.78.17 +117.27.241.99 +221.182.135.118 +182.243.62.48 +113.59.38.227 +113.107.44.93 +118.212.138.181 +219.157.114.80 +110.18.246.10 +218.76.105.168 +117.27.241.110 +218.12.228.38 +60.174.241.29 +115.153.176.80 +125.46.22.28 +120.221.64.229 +117.27.245.75 +121.18.230.47 +183.214.140.236 +125.46.22.31 +101.227.176.34 +58.216.110.2 +60.5.254.40 +122.228.24.167 +117.27.245.85 +219.146.68.84 +116.211.248.165 +218.7.220.40 60.5.254.10 -118.122.87.99 -221.179.172.161 -60.174.241.25 -113.207.72.15 -218.60.106.25 -183.250.179.32 -117.21.168.87 -182.140.147.63 -112.25.35.79 -60.174.241.26 -125.39.1.138 -221.179.172.204 -119.84.111.126 -61.167.54.62 -111.11.152.225 -114.80.143.144 -112.65.220.18 -113.207.69.17 -119.84.111.49 -222.211.64.92 -222.211.64.89 -111.11.228.69 -111.26.136.216 -202.201.14.181 -111.26.136.222 -111.1.59.190 -218.26.75.208 -36.250.76.204 -60.5.255.230 -101.70.152.37 -162.105.28.233 -58.20.164.51 -121.251.255.226 -202.98.156.62 -182.140.236.28 -182.132.33.43 -110.18.247.41 -110.18.247.40 -175.25.168.40 -111.1.59.93 -111.40.195.169 -121.251.255.227 -111.44.244.52 -222.211.64.51 -36.42.32.68 -119.84.111.113 -119.84.86.112 -218.58.222.15 -218.76.94.67 -111.20.250.62 -218.92.220.78 -218.202.111.106 -218.197.116.214 -124.164.8.65 -113.107.57.43 -117.187.19.45 -117.187.19.19 -117.187.19.17 -117.187.19.16 -117.187.19.18 -211.142.22.114 -117.169.17.8 -117.169.17.7 -117.169.17.6 -211.138.60.136 -125.90.204.117 -211.138.60.135 -202.120.1.32 -221.180.151.118 -58.20.197.62 -183.131.168.145 -122.228.233.206 -221.180.151.119 -122.228.233.209 -58.223.164.87 -202.194.19.4 -202.194.19.5 -36.250.248.66 -112.84.104.48 -111.26.17.169 -121.251.255.237 -124.165.216.64 -222.89.68.50 -117.131.213.238 -222.184.34.54 -112.25.35.61 -111.26.17.170 -117.156.21.51 -117.187.19.164 -60.215.125.71 -117.187.19.46 -36.250.248.68 -60.13.41.74 -36.250.76.37 -36.250.76.36 -36.250.76.35 -36.250.76.34 -222.89.68.51 -117.169.17.45 -218.199.110.85 -220.162.97.136 -42.58.243.157 -124.228.90.88 -14.215.100.94 -113.107.57.41 -14.215.9.85 -218.199.110.84 -58.63.233.35 -221.230.141.78 -117.21.204.77 -218.92.227.121 -116.211.79.27 -59.45.42.44 -122.228.233.208 -122.225.28.145 -111.11.228.70 -58.218.208.199 -183.134.11.90 -171.217.254.68 -61.184.117.53 -183.134.28.63 -116.57.77.35 -60.174.241.23 -183.134.12.69 -182.140.218.63 -182.140.218.64 -60.211.208.49 -218.86.111.69 -218.77.2.32 -61.163.117.65 -115.231.20.39 -117.169.17.46 -221.182.135.179 -121.14.117.145 -218.92.209.74 -182.106.194.107 -183.131.119.86 -183.224.12.87 -123.183.164.143 -106.3.62.213 -36.250.76.65 -106.3.62.211 -106.3.62.212 -183.131.168.154 -115.156.188.183 -115.156.188.182 -117.145.179.96 -222.186.132.68 -218.29.49.71 -112.25.55.143 150.138.214.95 -218.7.220.14 -59.56.30.221 -150.138.214.86 +36.248.10.49 150.138.214.85 -183.6.245.178 -150.138.214.83 -150.138.214.84 -122.13.74.252 -183.134.9.59 -124.116.133.50 -112.90.212.126 -218.60.132.160 -183.6.245.191 -14.215.100.95 -111.23.11.52 -115.153.176.80 -112.17.26.100 -117.23.2.85 -183.134.11.91 -221.182.135.156 -222.186.132.123 -125.90.206.144 -42.58.243.34 -183.61.26.199 -60.8.123.158 -150.138.169.233 -60.220.194.210 -36.42.32.254 -222.218.45.216 -117.27.241.99 -211.142.22.2 -59.56.30.207 -220.194.203.66 -218.5.238.215 -123.183.164.136 -112.65.220.227 -59.56.30.206 -111.47.201.207 -113.5.170.35 -112.25.82.12 +117.187.19.46 +123.128.14.197 +58.216.109.181 +220.194.200.177 +61.157.124.209 +150.138.169.29 +218.92.209.100 +123.138.60.143 +218.29.50.13 +59.63.80.126 +123.128.14.201 +117.27.245.62 +113.5.80.125 +101.227.176.34 +122.228.24.167 +110.18.244.142 +221.229.202.148 +218.29.50.48 +27.148.163.158 +60.174.241.27 +101.227.176.34 +218.92.209.100 +202.98.156.62 +182.140.236.27 +110.19.182.95 +101.227.176.34 +36.25.241.161 +101.227.176.34 +58.222.19.45 +101.227.176.34 +180.97.178.198 +101.227.176.34 49.79.232.225 -110.157.233.34 -221.180.137.59 -60.13.41.78 -183.131.119.87 -110.157.233.35 -183.134.16.86 -110.157.233.30 -110.157.233.33 -58.50.31.33 -123.138.60.192 -150.138.168.115 +101.227.176.34 61.147.211.20 -218.12.228.212 -119.90.19.39 -221.229.202.154 -123.138.157.109 -122.70.142.182 -60.223.208.78 -101.66.224.145 -180.97.247.157 -116.224.87.45 -180.97.180.16 -59.50.75.195 -211.91.165.175 -183.222.100.112 -183.131.192.83 -59.47.79.43 -211.91.168.40 -60.217.22.146 -183.214.140.236 -60.213.21.211 -218.60.51.253 -125.64.134.78 -222.163.202.216 -101.227.102.198 -223.111.13.62 -59.47.0.189 -117.23.2.86 -111.11.31.114 -123.172.120.115 -219.147.141.176 -120.221.24.123 \ No newline at end of file +101.227.176.34 +36.25.241.153 +117.131.213.238 \ No newline at end of file diff --git a/config/ticket_config.yaml b/config/ticket_config.yaml index da32a00b9ce4fd8dd1848db88a1baa948ae11cb0..9251eab95ab071441ef87efd261d6de29d8f9c1a 100644 --- a/config/ticket_config.yaml +++ b/config/ticket_config.yaml @@ -24,6 +24,7 @@ #is_aotu_code是否自动打码,如果选择Ture,则调用打码兔打码,默认不使用打码兔 #aotu_code_type 1为打码兔,2为若快 #is_email: 是否需要邮件通知 ex: True or False 切记,邮箱加完一定到config目录下测试emailConf功能是否正常 +#is_cdn: 1为需要,2位本机ip查询 #邮箱配置 列举163 # email: "xxx@163.com" @@ -41,29 +42,17 @@ set: station_dates: -# - "2018-01-27" -# - "2018-01-28" -# - "2018-02-22" - - "2018-02-24" + - "2018-02-02" station_trains: - - "D2879" + - "G2366" - "D1813" - "D2975" - "D1825" - "D1829" - "D2841" - "D1833" -# - "K4300" -# - "K5226" -# - "K7772" -# - "G1329" -# - "G1359" -# - "G1361" -# - "G1373" -# - "G1363" -# - "G4933" - from_station: "三江南" - to_station: "广州南" + from_station: "邵阳" + to_station: "上海" set_type: - "一等座" - "二等座" @@ -74,7 +63,7 @@ set: 12306count: # - uesr: "" # - pwd: "apple1995" - - uesr: "931128603@qq.com" + - uesr: "@qq.com" - pwd: "QWERTY" select_refresh_interval: 0.4 @@ -84,14 +73,14 @@ aotu_code_type: 2 #enable_proxy: False damatu: - uesr: "931128603" + uesr: "" pwd: "qazWSX1995" email_conf: is_email: True - email: "931128603@qq.com " + email: "@qq.com " notice_email_list: "61995120@qq.com" - username: "931128603" + username: "" password: "xwopwxbkupbqbfgb" host: "smtp.qq.com" diff --git a/config/urlConf.py b/config/urlConf.py index dbd9401f53ff9a59ae994856bca640e4988b0049..5b16164cb9eaa8bf6d692894cbf420f375ea49eb 100644 --- a/config/urlConf.py +++ b/config/urlConf.py @@ -6,7 +6,7 @@ urls = { "auth": { "req_url": "/passport/web/auth/uamtk", "req_type": "post", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -16,7 +16,7 @@ urls = { "login": { "req_url": "/passport/web/login", "req_type": "post", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/login/init", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -25,9 +25,9 @@ urls = { }, "getCodeImg": { - "req_url": "/passport/captcha/captcha-image?login_site=E&module=login&rand=sjrand&{0}".format(random.random()), + "req_url": "/passport/captcha/captcha-image?login_site=E&module=login&rand=sjrand&{0}", "req_type": "get", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/login/init", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -37,7 +37,7 @@ urls = { "codeCheck": { "req_url": "/passport/captcha/captcha-check", "req_type": "post", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/login/init", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -47,9 +47,9 @@ urls = { "loginInit": { "req_url": "/otn/login/init", "req_type": "get", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/index/init", "Host": "kyfw.12306.cn", - "re_try": 1, + "re_try": 10, "re_time": 0.1, "is_logger": False, "is_json": False, @@ -57,7 +57,7 @@ urls = { "getUserInfo": { "req_url": "/otn/index/initMy12306", "req_type": "get", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -67,7 +67,7 @@ urls = { "userLogin": { "req_url": "/otn/login/userLogin", "req_type": "get", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -77,7 +77,7 @@ urls = { "uamauthclient": { "req_url": "/otn/uamauthclient", "req_type": "post", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -87,7 +87,7 @@ urls = { "initdc_url": { "req_url": "/otn/confirmPassenger/initDc", "req_type": "get", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/leftTicket/init", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -97,7 +97,7 @@ urls = { "get_passengerDTOs": { "req_url": "/otn/confirmPassenger/getPassengerDTOs", "req_type": "post", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -107,7 +107,7 @@ urls = { "select_url": { "req_url": "/otn/leftTicket/queryZ?leftTicketDTO.train_date={0}&leftTicketDTO.from_station={1}&leftTicketDTO.to_station={2}&purpose_codes=ADULT", "req_type": "post", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/leftTicket/init", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -117,17 +117,17 @@ urls = { "check_user_url": { "req_url": "/otn/login/checkUser", "req_type": "post", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/leftTicket/init", "Host": "kyfw.12306.cn", - "re_try": 1, - "re_time": 0.1, + "re_try": 10, + "re_time": 0.3, "is_logger": True, "is_json": True, }, "submit_station_url": { "req_url": "/otn/leftTicket/submitOrderRequest", "req_type": "post", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/leftTicket/init", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -137,7 +137,7 @@ urls = { "checkOrderInfoUrl": { "req_url": "/otn/confirmPassenger/checkOrderInfo", "req_type": "post", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -147,7 +147,7 @@ urls = { "getQueueCountUrl": { "req_url": "/otn/confirmPassenger/getQueueCount", "req_type": "post", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -157,7 +157,7 @@ urls = { "checkQueueOrderUrl": { "req_url": "/otn/confirmPassenger/confirmSingleForQueue", "req_type": "post", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -167,7 +167,7 @@ urls = { "checkRandCodeAnsyn": { "req_url": "/otn/passcodeNew/checkRandCodeAnsyn", "req_type": "post", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -177,7 +177,7 @@ urls = { "codeImgByOrder": { "req_url": "/otn/passcodeNew/getPassCodeNew?module=passenger&rand=randp&%s" % random.random(), "req_type": "post", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -187,7 +187,7 @@ urls = { "queryOrderWaitTimeUrl": { "req_url": "/otn/confirmPassenger/queryOrderWaitTime", "req_type": "post", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -197,7 +197,7 @@ urls = { "queryMyOrderNoCompleteUrl": { "req_url": "/otn/queryOrder/queryMyOrderNoComplete", "req_type": "post", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/queryOrder/initNoComplete", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -207,7 +207,7 @@ urls = { "initNoCompleteUrl": { "req_url": "/otn/queryOrder/initNoComplete", "req_type": "post", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/queryOrder/initNoComplete", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, @@ -217,7 +217,7 @@ urls = { "cancelNoCompleteMyOrder": { "req_url": "/otn/queryOrder/cancelNoCompleteMyOrder", "req_type": "post", - "Referer": "", + "Referer": "https://kyfw.12306.cn/otn/queryOrder/initNoComplete", "Host": "kyfw.12306.cn", "re_try": 10, "re_time": 0.1, diff --git a/init/login.py b/init/login.py index 0a820f517f6a4f0b2b13ef69b340d3ae90c05221..73036ec55744eee2b482ad571fc4b81a0863317b 100644 --- a/init/login.py +++ b/init/login.py @@ -24,7 +24,7 @@ class GoLogin: self.aotu_code_type = aotu_code_type def cookietp(self): - print("正在获取cookie") + print(u"正在获取cookie") url = self.urlConf["loginInit"] self.httpClint.send(url) # Url = "https://kyfw.12306.cn/otn/login/init" @@ -67,12 +67,12 @@ class GoLogin: 3.控制台输入对应下标,按照英文逗号分开,即可手动完成打码, :return: """ - print ("下载验证码...") + print (u"下载验证码...") codeimgUrl = code_url img_path = './tkcode' result = self.httpClint.send(codeimgUrl) try: - print("下载验证码成功") + print(u"下载验证码成功") open(img_path, 'wb').write(result) except OSError as e: print (e) @@ -83,7 +83,7 @@ class GoLogin: :return: str """ if is_raw_input: - Ofset = raw_input("请输入验证码: ") + Ofset = raw_input(u"请输入验证码: ") select = Ofset.split(',') post = [] offsetsX = 0 # 选择的答案的left值,通过浏览器点击8个小图的中点得到的,这样基本没问题 @@ -118,7 +118,7 @@ class GoLogin: post.append(offsetsX) post.append(offsetsY) randCode = str(post).replace(']', '').replace('[', '').replace("'", '').replace(' ', '') - print("验证码识别坐标为{0}".format(randCode)) + print(u"验证码识别坐标为{0}".format(randCode)) return randCode def auth(self): @@ -141,7 +141,7 @@ class GoLogin: } fresult = self.httpClint.send(codeCheck, codeCheckData) if "result_code" in fresult and fresult["result_code"] == "4": - print ("验证码通过,开始登录..") + print (u"验证码通过,开始登录..") return True else: if "result_message" in fresult: @@ -164,7 +164,7 @@ class GoLogin: } tresult = self.httpClint.send(logurl, logData) if 'result_code' in tresult and tresult["result_code"] == 0: - print ("登录成功") + print (u"登录成功") tk = self.auth() if "newapptk" in tk and tk["newapptk"]: return tk["newapptk"] @@ -172,11 +172,11 @@ class GoLogin: return False elif 'result_message' in tresult and tresult['result_message']: messages = tresult['result_message'] - if messages.find("密码输入错误") is not -1: + if messages.find(u"密码输入错误") is not -1: raise UserPasswordException("{0}".format(messages)) else: - print ("登录失败: {0}".format(messages)) - print ("尝试重新登陆") + print (u"登录失败: {0}".format(messages)) + print (u"尝试重新登陆") return False else: return False @@ -187,14 +187,14 @@ class GoLogin: :return: """ if not uamtk: - return "权限校验码不能为空" + return u"权限校验码不能为空" else: uamauthclientUrl = self.urlConf["uamauthclient"] data = {"tk": uamtk} uamauthclientResult = self.httpClint.send(uamauthclientUrl, data) if uamauthclientResult: if "result_code" in uamauthclientResult and uamauthclientResult["result_code"] == 0: - print("欢迎 {} 登录".format(uamauthclientResult["username"])) + print(u"欢迎 {} 登录".format(uamauthclientResult["username"])) return True else: return False @@ -213,14 +213,15 @@ class GoLogin: if self.is_aotu_code and self.aotu_code_type == 1: balance = DamatuApi(_get_yaml()["damatu"]["uesr"], _get_yaml()["damatu"]["pwd"]).getBalance() if int(balance) < 40: - raise balanceException('余额不足,当前余额为: {}'.format(balance)) + raise balanceException(u'余额不足,当前余额为: {}'.format(balance)) user, passwd = _get_yaml()["set"]["12306count"][0]["uesr"], _get_yaml()["set"]["12306count"][1]["pwd"] if not user or not passwd: - raise UserPasswordException("温馨提示: 用户名或者密码为空,请仔细检查") + raise UserPasswordException(u"温馨提示: 用户名或者密码为空,请仔细检查") login_num = 0 while True: self.cookietp() self.httpClint.set_cookies(_jc_save_wfdc_flag="dc", _jc_save_fromStation="%u4E0A%u6D77%u8679%u6865%2CAOH", _jc_save_toStation="%u5170%u5DDE%u897F%2CLAJ", _jc_save_fromDate="2018-02-14", _jc_save_toDate="2018-01-16", RAIL_DEVICEID="EN_3_EGSe2GWGHXJeCkFQ52kHvNCrNlkz9n1GOqqQ1wR0i98WsD8Gj-a3YHZ-XYKeESWgCiJyyucgSwkFOzVHhHqfpidLPcm2vK9n83uzOPuShO3Pl4lCydAtQu4BdFqz-RVmiduNFixrcrN_Ny43135JiEtqLaI") + self.urlConf["getCodeImg"]["req_url"] = self.urlConf["getCodeImg"]["req_url"].format(random.random()) self.readImg(self.urlConf["getCodeImg"]) self.randCode = self.getRandCode() login_num += 1 @@ -235,9 +236,9 @@ class GoLogin: url = 'https://kyfw.12306.cn/otn/login/loginOut' result = myurllib2.get(url) if result: - print ("已退出") + print (u"已退出") else: - print ("退出失败") + print (u"退出失败") # if __name__ == "__main__": diff --git a/init/select_ticket_info.py b/init/select_ticket_info.py index 26ba62bc646a5c0c148cdb80506513b0804fa7e5..efb0cc3690a36db92409e864c4b92907f2e658ae 100644 --- a/init/select_ticket_info.py +++ b/init/select_ticket_info.py @@ -1,6 +1,7 @@ # -*- coding=utf-8 -*- import datetime import json +import random import re import socket import sys @@ -31,6 +32,7 @@ class select: self.from_station, self.to_station, self.station_dates, self._station_seat, self.is_more_ticket, self.ticke_peoples, self.select_refresh_interval, self.station_trains, self.ticket_black_list_time = self.get_ticket_info() self.is_aotu_code = _get_yaml()["is_aotu_code"] self.aotu_code_type = _get_yaml()["aotu_code_type"] + self.is_cdn = _get_yaml()["is_cdn"] self.order_request_params = {} # 订单提交时的参数 self.ticketInfoForPassengerForm = {} # 初始化当前页面参数 self.current_seats = {} # 席别信息 @@ -63,7 +65,7 @@ class select: station_trains = ticket_info_config["set"]["station_trains"] ticket_black_list_time = ticket_info_config["ticket_black_list_time"] print "*"*20 - print "当前配置:出发站:{0}\n到达站:{1}\n乘车日期:{2}\n坐席:{3}\n是否有票自动提交:{4}\n乘车人:{5}\n刷新间隔:{6}\n候选购买车次:{7}\n僵尸票关小黑屋时长:{8}\n".format\ + print u"当前配置:出发站:{0}\n到达站:{1}\n乘车日期:{2}\n坐席:{3}\n是否有票自动提交:{4}\n乘车人:{5}\n刷新间隔:{6}\n候选购买车次:{7}\n僵尸票关小黑屋时长:{8}\n".format\ ( from_station, to_station, @@ -203,8 +205,8 @@ class select: elif 'messages' in jsonData and jsonData['messages']: print(jsonData['messages'][0]) else: - print("未查找到常用联系人") - raise PassengerUserException("未查找到常用联系人,请先添加联系人在试试") + print(u"未查找到常用联系人") + raise PassengerUserException(u"未查找到常用联系人,请先添加联系人在试试") def submitOrderRequestFunc(self, from_station, to_station, station_date=None): self.confUrl["select_url"]["req_url"] = self.confUrl["select_url"]["req_url"].format( @@ -231,7 +233,7 @@ class select: for station_ticket in station_tickets: value = station_ticket['data'] if not value: - print ('{0}-{1} 车次坐席查询为空...'.format(self.from_station, self.to_station)) + print (u'{0}-{1} 车次坐席查询为空...'.format(self.from_station, self.to_station)) else: if value['result']: for i in value['result']: @@ -244,13 +246,13 @@ class select: # tiket_values = [k for k in value['map'].values()] self.secretStr = ticket_info[0] train_no = ticket_info[3] - print ('车次: ' + train_no + ' 始发车站: ' + self.from_station + ' 终点站: ' + + print (u'车次: ' + train_no + ' 始发车站: ' + self.from_station + ' 终点站: ' + self.to_station + ' ' + self._station_seat[j].encode("utf8") + ':' + ticket_info[self.station_seat(self._station_seat[j].encode("utf8"))]) if self.ticket_black_list.has_key(train_no) and (datetime.datetime.now() - self.ticket_black_list[train_no]).seconds/60 < int(self.ticket_black_list_time): - print("该车次{} 正在被关小黑屋,跳过此车次".format(train_no)) + print(u"该车次{} 正在被关小黑屋,跳过此车次".format(train_no)) break else: - print ('正在尝试提交订票...') + print (u'正在尝试提交订票...') # self.submitOrderRequestFunc(from_station, to_station, self.time()) self.submit_station() @@ -266,7 +268,7 @@ class select: pass # time.sleep(self.expect_refresh_interval) else: - print "车次配置信息有误,或者返回数据异常,请检查 {}".format(station_ticket) + print u"车次配置信息有误,或者返回数据异常,请检查 {}".format(station_ticket) def check_user(self): """ @@ -281,13 +283,13 @@ class select: self.is_check_user["user_time"] = datetime.datetime.now() else: if check_user['messages']: - print ('用户检查失败:%s,可能未登录,可能session已经失效' % check_user['messages'][0]) - print ('正在尝试重新登录') + print (u'用户检查失败:%s,可能未登录,可能session已经失效' % check_user['messages'][0]) + print (u'正在尝试重新登录') self.call_login() self.is_check_user["user_time"] = datetime.datetime.now() else: - print ('用户检查失败: %s,可能未登录,可能session已经失效' % check_user) - print ('正在尝试重新登录') + print (u'用户检查失败: %s,可能未登录,可能session已经失效' % check_user) + print (u'正在尝试重新登录') self.call_login() self.is_check_user["user_time"] = datetime.datetime.now() @@ -313,9 +315,9 @@ class select: submitResult = self.httpClint.send(submit_station_url, data) if 'data' in submitResult and submitResult['data']: if submitResult['data'] == 'N': - print ('出票成功') + print (u'出票成功') else: - print ('出票失败') + print (u'出票失败') elif 'messages' in submitResult and submitResult['messages']: raise ticketIsExitsException(submitResult['messages'][0]) @@ -352,7 +354,7 @@ class select: passengerTicketStrList = [] oldPassengerStr = [] if not self.user_info: - raise PassengerUserException("联系人不在列表中,请查证后添加") + raise PassengerUserException(u"联系人不在列表中,请查证后添加") if len(self.user_info) is 1: passengerTicketStrList.append( '0,' + self.user_info[0]['passenger_type'] + "," + self.user_info[0][ @@ -394,12 +396,10 @@ class select: if 'data' in checkOrderInfo: if "ifShowPassCode" in checkOrderInfo["data"] and checkOrderInfo["data"]["ifShowPassCode"] == "Y": is_need_code = True - t = threading.Thread(target=self.callRandCode()) - t.start() if self.getQueueCount(train_no, set_type, is_need_code): return True if "ifShowPassCode" in checkOrderInfo["data"] and checkOrderInfo['data']['submitStatus'] is True: - print ('车票提交通过,正在尝试排队') + print (u'车票提交通过,正在尝试排队') is_need_code = False if self.getQueueCount(train_no, set_type, is_need_code): return True @@ -442,25 +442,25 @@ class select: countT = getQueueCountResult["data"]["countT"] if int(countT) is 0: if int(ticket_split) < len(self.user_info): - print("当前余票数小于乘车人数,放弃订票") + print(u"当前余票数小于乘车人数,放弃订票") else: - print("排队成功, 当前余票还剩余: {0} 张".format(ticket_split)) + print(u"排队成功, 当前余票还剩余: {0} 张".format(ticket_split)) if self.checkQueueOrder(is_need_code): return True else: - print("当前排队人数:" + str(countT) + "当前余票还剩余:{0} 张,继续排队中".format(ticket_split)) + print(u"当前排队人数: {1} 当前余票还剩余:{0} 张,继续排队中".format(ticket_split, countT)) else: - print("排队发现未知错误{0},将此列车 {1}加入小黑屋".format(getQueueCountResult, train_no)) + print(u"排队发现未知错误{0},将此列车 {1}加入小黑屋".format(getQueueCountResult, train_no)) self.ticket_black_list[train_no] = datetime.datetime.now() elif "messages" in getQueueCountResult and getQueueCountResult["messages"]: - print("排队异常,错误信息:{0}, 将此列车 {1}加入小黑屋".format(getQueueCountResult["messages"][0], train_no)) + print(u"排队异常,错误信息:{0}, 将此列车 {1}加入小黑屋".format(getQueueCountResult["messages"][0], train_no)) self.ticket_black_list[train_no] = datetime.datetime.now() else: if "validateMessages" in getQueueCountResult and getQueueCountResult["validateMessages"]: print(str(getQueueCountResult["validateMessages"])) self.ticket_black_list[train_no] = datetime.datetime.now() else: - print("未知错误 {0}".format("".join(getQueueCountResult))) + print(u"未知错误 {0}".format("".join(getQueueCountResult))) def checkRandCodeAnsyn(self, randCode): """ @@ -502,40 +502,40 @@ class select: try: if is_node_code: - print("正在使用自动识别验证码功能") + print(u"正在使用自动识别验证码功能") for i in range(3): codeImgByOrder = self.confUrl["codeImgByOrder"] self.login.readImg(codeImgByOrder) randCode = self.login.getRandCode() checkcode = self.checkRandCodeAnsyn(randCode) if checkcode == 'TRUE': - print("验证码通过,正在提交订单") + print(u"验证码通过,正在提交订单") data['randCode'] = randCode break else: - print ("验证码有误, {0}次尝试重试".format(i+1)) - print("验证码超过限定次数3次,放弃此次订票机会!") + print (u"验证码有误, {0}次尝试重试".format(i+1)) + print(u"验证码超过限定次数3次,放弃此次订票机会!") else: - print("不需要验证码") + print(u"不需要验证码") time.sleep(0.5) checkQueueOrderResult = self.httpClint.send(checkQueueOrderUrl, data) 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("提交订单成功!") + print(u"提交订单成功!") self.queryOrderWaitTime() else: if 'errMsg' in c_data and c_data['errMsg']: - print("提交订单失败,{0}".format(c_data['errMsg'])) + print(u"提交订单失败,{0}".format(c_data['errMsg'])) else: print(c_data) - print('订票失败!很抱歉,请重试提交预订功能!') + print(u'订票失败!很抱歉,请重试提交预订功能!') elif "messages" in checkQueueOrderResult and checkQueueOrderResult["messages"]: - print("提交订单失败,错误信息: " + checkQueueOrderResult["messages"]) + print(u"提交订单失败,错误信息: " + checkQueueOrderResult["messages"]) else: - print("提交订单中,请耐心等待:" + checkQueueOrderResult["message"]) + print(u"提交订单中,请耐心等待:" + checkQueueOrderResult["message"]) except ValueError: - print("接口 {} 无响应".format(checkQueueOrderUrl)) + print(u"接口 {} 无响应".format(checkQueueOrderUrl)) def queryOrderWaitTime(self): """ @@ -547,7 +547,7 @@ class select: _random = int(round(time.time() * 1000)) num += 1 if num > 30: - print("超出排队时间,自动放弃,正在重新刷票") + print(u"超出排队时间,自动放弃,正在重新刷票") order_id = self.queryMyOrderNoComplete() # 排队失败,自动取消排队订单 if order_id: self.cancelNoCompleteMyOrder(order_id) @@ -561,25 +561,25 @@ class select: if queryOrderWaitTimeResult: if "status" in queryOrderWaitTimeResult and queryOrderWaitTimeResult["status"]: if "orderId" in queryOrderWaitTimeResult["data"] and queryOrderWaitTimeResult["data"]["orderId"] is not None: - sendEmail("恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!".format(queryOrderWaitTimeResult["data"]["orderId"])) - raise ticketIsExitsException("恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!".format(queryOrderWaitTimeResult["data"]["orderId"])) + sendEmail(u"恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!".format(queryOrderWaitTimeResult["data"]["orderId"])) + raise ticketIsExitsException(u"恭喜您订票成功,订单号为:{0}, 请立即打开浏览器登录12306,访问‘未完成订单’,在30分钟内完成支付!".format(queryOrderWaitTimeResult["data"]["orderId"])) elif "msg" in queryOrderWaitTimeResult["data"] and queryOrderWaitTimeResult["data"]["msg"]: print queryOrderWaitTimeResult["data"]["msg"] break elif "waitTime"in queryOrderWaitTimeResult["data"] and queryOrderWaitTimeResult["data"]["waitTime"]: - print("排队等待时间预计还剩 {0} ms".format(0-queryOrderWaitTimeResult["data"]["waitTime"])) + print(u"排队等待时间预计还剩 {0} ms".format(0-queryOrderWaitTimeResult["data"]["waitTime"])) else: print ("正在等待中") elif "messages" in queryOrderWaitTimeResult and queryOrderWaitTimeResult["messages"]: - print("排队等待失败: " + queryOrderWaitTimeResult["messages"]) + print(u"排队等待失败: " + queryOrderWaitTimeResult["messages"]) else: - print("第{}次排队中,请耐心等待".format(num+1)) + print(u"第{}次排队中,请耐心等待".format(num+1)) else: - print("排队中") + print(u"排队中") time.sleep(2) else: - print(ticketNumOutException("订单提交失败!,正在重新刷票")) + print(ticketNumOutException(u"订单提交失败!,正在重新刷票")) def queryMyOrderNoComplete(self): """ @@ -608,7 +608,7 @@ class select: else: return False else: - print("接口 {} 无响应".format(queryMyOrderNoCompleteUrl)) + print(u"接口 {} 无响应".format(queryMyOrderNoCompleteUrl)) def initNoComplete(self): """ @@ -634,19 +634,24 @@ class select: } cancelNoCompleteMyOrderResult = self.httpClint.send(cancelNoCompleteMyOrderUrl, cancelNoCompleteMyOrderData) if "data" in cancelNoCompleteMyOrderResult and "existError" in cancelNoCompleteMyOrderResult["data"] and cancelNoCompleteMyOrderResult["data"]["existError"] == "N": - print("排队超时,已为您自动取消订单,订单编号: {0}".format(sequence_no)) + print(u"排队超时,已为您自动取消订单,订单编号: {0}".format(sequence_no)) time.sleep(2) return True else: - print("排队超时,取消订单失败, 订单号{0}".format(sequence_no)) + print(u"排队超时,取消订单失败, 订单号{0}".format(sequence_no)) 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 = self.cdn_list + if self.is_cdn == 1: + while True: + if self.cdn_list: + self.httpClint.cdn = self.cdn_list[random.randint(0, len(self.cdn_list)-1)] + break + else: + pass def call_login(self, auth=False): """ @@ -658,17 +663,37 @@ class select: else: self.login.go_login() - def main(self): - is_cdn = _get_yaml()["is_cdn"] - if is_cdn == 1: + def cdn_req(self, cdn): + for i in range(len(cdn)-1): + http = HTTPClient() + urls = self.confUrl["loginInit"] + start_time = datetime.datetime.now() + http.cdn = cdn[i].replace("\n", "") + rep = http.send(urls) + if rep and "message" not in rep and (datetime.datetime.now() - start_time).microseconds / 1000 < 400: + self.cdn_list.append(cdn[i].replace("\n", "")) + + def cdn_certification(self): + """ + cdn 认证 + :return: + """ + if self.is_cdn == 1: CDN = CDNProxy() - self.cdn_list = CDN.all_cdn() - if self.cdn_list: - print("开启cdn查询") - print("本次cdn总数为{}".format(len(self.cdn_list))) - self.set_cdn() + all_cdn = CDN.all_cdn() + if all_cdn: + print(u"开启cdn查询") + print(u"本次待筛选cdn总数为{}".format(len(all_cdn))) + t = threading.Thread(target=self.cdn_req, args=(all_cdn,)) + t.start() else: - raise ticketConfigException("cdn列表为空,请先加载cdn") + raise ticketConfigException(u"cdn列表为空,请先加载cdn") + else: + pass + + def main(self): + self.cdn_certification() + self.set_cdn() self.call_login() from_station, to_station = self.station_table(self.from_station, self.to_station) self.check_user() @@ -682,14 +707,17 @@ class select: self.check_user() time.sleep(self.select_refresh_interval) if time.strftime('%H:%M:%S', time.localtime(time.time())) > "23:00:00": - print "12306休息时间,本程序自动停止,明天早上6点将自动运行" + print u"12306休息时间,本程序自动停止,明天早上6点将自动运行" time.sleep(60 * 60 * 7) 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) - if is_cdn == 1: - self.set_cdn() + print u"正在第{0}次查询 乘车日期: {1} 车次{2} 查询无票 cdn轮询IP {4} 当前cdn总数{5} 总耗时{3}ms".format(num, + ",".join(self.station_dates), + ",".join(self.station_trains), + (datetime.datetime.now()-start_time).microseconds/1000, self.httpClint.cdn, + len(self.cdn_list)) + self.set_cdn() except PassengerUserException as e: print e.message break @@ -707,13 +735,13 @@ class select: break except ValueError as e: if e.message == "No JSON object could be decoded": - print("12306接口无响应,正在重试") + print(u"12306接口无响应,正在重试") else: print(e.message) except KeyError as e: print(e.message) except TypeError as e: - print("12306接口无响应,正在重试 {0}".format(e.message)) + print(u"12306接口无响应,正在重试 {0}".format(e.message)) except socket.error as e: print(e.message) diff --git a/myUrllib/httpUtils.py b/myUrllib/httpUtils.py index 3023d26670d2c777d517b3e42b5cb0bb3f926dc9..fe2abd223091795af02137e6894fdef9170dde45 100644 --- a/myUrllib/httpUtils.py +++ b/myUrllib/httpUtils.py @@ -90,7 +90,8 @@ class HTTPClient(object): """send request to url.If response 200,return response, else return None.""" allow_redirects = False is_logger = urls["is_logger"] - error_data = {"code": 99999, "message": "重试次数达到上限"} + error_data = {"code": 99999, "message": u"重试次数达到上限"} + self.setHeadersReferer(urls["Referer"]) if data: method = "post" self.setHeaders({"Content-Length": "{0}".format(len(data))}) @@ -107,7 +108,6 @@ class HTTPClient(object): 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=2, @@ -116,7 +116,6 @@ class HTTPClient(object): allow_redirects=allow_redirects, verify=False, **kwargs) - print(response.status_code) if response.status_code == 200: if response.content: if is_logger: diff --git a/tkcode b/tkcode index 5b9e8f4df9203edbeeeca16ac1d17cdf0f63e929..67b51691e3728e1640c96b9991978de973f970c1 100644 Binary files a/tkcode and b/tkcode differ