-
-
Save pingf/da8f77183bcc5fdec4638960176075bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 | |
# -*- coding:utf-8 -*- | |
import requests | |
import time | |
import hashlib | |
from Crypto.Cipher import AES | |
import base64 | |
import json | |
# 生成秘钥 | |
def random_key(): | |
date = time.strftime("%Y-%m-%d", time.localtime()) | |
date_reverse = date[::-1] | |
md5 = hashlib.md5(date_reverse).hexdigest() | |
return md5[8:24] | |
# 解密 | |
def decrypt(value): | |
key = random_key() | |
value = base64.b64decode(value) | |
result = AES.new(key, AES.MODE_ECB).decrypt(value) | |
pad = ord(result[-1]) | |
return result[:-pad] | |
# 获取所有车辆 | |
def get_all_line(): | |
url = 'https://wap.zhengzhoubus.com/buswechat/WifiBusInterface/transfer/line!getAllLines.action' | |
req = requests.get(url) | |
res = json.loads(req.text) | |
return res | |
# 获取指定线路所有站点 | |
def get_all_station_by_line(no): | |
url = 'https://wap.zhengzhoubus.com/buswechat/WifiBusInterface/transfer/line!getLineAll.action' | |
params = {'lineName': no} | |
req = requests.post(url, params) | |
res = json.loads(req.text) | |
return res | |
# 获取指定方向线路所有车辆 | |
def get_all_bus_by_line(no, direction): | |
url = 'https://wap.zhengzhoubus.com/buswechat/WifiBusInterface/transfer/bus!WaitBusLine.action' | |
params = {'lineNo': no, 'isUpDown': direction} | |
req = requests.get(url, params) | |
res = req.text.replace('\r\n', '') | |
return json.loads(decrypt(res)) | |
# 判断线路是否存在 | |
def line_exist(no): | |
for info in line_list: | |
if str(no) == info['line_no']: | |
return True | |
return False | |
# 判断站点是否存在 | |
def station_exist(stat): | |
for info in line_station[direction]['stations']: | |
if str(stat) == info['stationId']: | |
return True | |
return False | |
# 获取站点顺序 | |
def get_station_no(stat): | |
i = 0 | |
for info in line_station[direction]['stations']: | |
if str(stat) == info['stationId']: | |
return i | |
i = i + 1 | |
line_list = get_all_line() | |
# step 1: 获取线路 | |
line = 79 | |
while not line_exist(line): | |
line = input('输入线路: ') | |
line_station = get_all_station_by_line(line) | |
# step 2: 获取方向 | |
direction = 1 | |
while direction not in [0, 1]: | |
print(line_station[0]['isUpDown'] + ': ' + line_station[0]['stations'][0]['stationName'] + ' -> ' + | |
line_station[0]['stations'][-1]['stationName']) | |
print(line_station[1]['isUpDown'] + ': ' + line_station[1]['stations'][0]['stationName'] + ' -> ' + | |
line_station[1]['stations'][-1]['stationName']) | |
direction = input('输入方向: ') | |
# step 3: 获取站点 | |
station = 136325 | |
while not station_exist(station): | |
for station_item in line_station[direction]['stations']: | |
print(station_item['stationId'] + ': ' + station_item['stationName']) | |
station = input('输入站点: ') | |
station_no = get_station_no(station) | |
# 获取车辆 | |
line_bus = get_all_bus_by_line(line, direction) | |
line_bus_info = {} | |
for bus_item in line_bus['bus']: | |
line_bus_info[bus_item['labelNo']] = bus_item | |
sorted(line_bus_info) | |
count = 0 | |
for bus_key in sorted(line_bus_info.keys()): | |
if count >= 3: | |
break | |
if station_no <= int(line_bus_info[bus_key]['labelNo']): | |
count = count + 1 | |
print(str(line_bus_info[bus_key]['busNo']) + | |
': 距离' + str((int(line_bus_info[bus_key]['labelNo']) - int(station_no))) + | |
' 进站' + str(line_bus_info[bus_key]['onStation'])) | |
print(line_bus_info[bus_key]['labelNo']) | |
print(station_no) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment