首页 公交地铁查询 公交地铁查询示例代码 换乘查询[Python]

换乘查询示例代码[Python]

作者:liuxiaojie 阅读数:1892 上传时间:2016-03-10

换乘查询

#!/usr/bin/python
# encoding:utf-8

import urllib2, json, urllib, time


# 2、换乘查询

data = {}
data["appkey"] = "your_appkey_here"
data["start"] = "西溪竞舟苑"  #杭州
data["end"] = "杭州汽车北站"  #utf8
data["city"] = "杭州"
data["type"] =""
url_values = urllib.urlencode(data)
url = "https://api.jisuapi.com/transit/station2s" + "?" + url_values
request = urllib2.Request(url)
result = urllib2.urlopen(request)
jsonarr = json.loads(result.read())

if jsonarr["status"] != u"0":
    print jsonarr["msg"]
    exit()
result = jsonarr["result"][0]

#此处为公交换乘的参数
print result["totaldistance"],result["totalduration"],result["totalprice"],result["arrivetime"],result["tiptype"],result["totalstopnum"],result["totalwalkdistance"],result["vehicles"][0]
for val in result["steps"] :
    print val["distance"],val["duration"],val["type"],val["steptext"]