用python查询德累斯顿公共交通系统当前的公交车站数据
dvb的Python项目详细描述
一个非官方的python模块,提供了一些查询 德累斯顿公共访问api方法的集合 运输系统。
如果您正在node.js中查找类似的内容,请查看 dvbjs。还是斯威夫特? 见DVB。
文档位于here。
从pypi获取dvbpy:)
pip install dvbpy
然后直接导入。
importdvb
监视一次停止
监视一个站点,以查看每辆公共汽车或电车在 指定的时间偏移量。
importdvbstop='Helmholtzstraße'time_offset=0# how many minutes in the future, 0 for nownum_results=2city='Dresden'dvb.monitor(stop,time_offset,num_results,city)
[{'line':'85','direction':'Striesen','arrival':5},{'line':'85','direction':'Löbtau Süd','arrival':7}]
您也可以调用monitor(),而不使用city、num_结果或 时间偏移。城市将默认为德累斯顿。
查找路线
向服务器查询从一个站点到另一个站点的可能路由。退货 多个可能的行程,要乘坐的公共汽车/电车线路,单程 停靠点、到达和离开时间以及GPS坐标。
importdvbimporttimeorigin='Zellescher Weg'city_origin='Dresden'destination='Postplatz'city_destination='Dresden'time=int(time.time())# a unix timestamp is wanted heredeparr='dep'# set to 'arr' for arrival time, 'dep' for departure timedvb.route(origin,destination,city_origin,city_destination,time,deparr)
{'trips':[{'interchange':0,'nodes':[{'line':'11','mode':'Straßenbahn','direction':'Dresden Bühlau Ullersdorfer Platz','path':[[13.745754,51.02816],[13.745848,51.028393],...],'departure':{'time':'18:01','stop':'Zellescher Weg','coords':'13745754,51028160'},'arrival':{'time':'18:14','stop':'Postplatz','coords':'13733717,51050544'}}],'duration':'00:13','departure':'18:01','arrival':'18:14'},...}],'origin':'Dresden, Zellescher Weg','destination':'Dresden, Postplatz'}
除了出发地和目的地以外的一切都是可选的,只需要 必要时包括在内。始发地和目的地城市默认为 德累斯顿,时间到现在,按出发时间办理。
path属性包含一个包含所有坐标的列表 描述此节点的路径。例如,如果要绘制 在地图上。
按名称查找站点
在DVB网络中搜索一个站点。
importdvbdvb.find('zellesch')
[{'name':'Zellescher Weg','city':'Dresden','coords':[51.028366,13.745847]}]
字段city和coords是可选的,因为它们不是 每一站都有。所以别忘了检查他们的存在 第一。
[stopforstopindvb.find('Post')if'city'instopifstop['city']=='Dresden']
使用坐标查找其他poi
在给定的正方形内搜索各种poi。
importdvbsouthwest_lat=51.04120southwest_lng=13.70106northeast_lat=51.04615northeast_lng=13.71368pintypes='stop'# can be poi, platform, rentabike, ticketmachine, parkandride, carsharing or stopdvb.pins(southwest_lat,southwest_lng,northeast_lat,northeast_lng,pintypes)
pintypes如果没有其他输入,则默认为“stop”。
[{"connections":"1:7~8~9~10~11~12","coords":{"lat":51.04373256804444,"lng":13.70625638110702},"id":33000143,"name":"Saxoniastraße"},{"connections":"2:61~90","coords":{"lat":51.04159705545878,"lng":13.7053650905211},"id":33000700,"name":"Ebertplatz"},{"connections":"1:6~7~8~9~10~11~12#2:61~63~90~A#3:333","coords":{"lat":51.04372841952444,"lng":13.703461228676069},"id":33000144,"name":"Tharandter Straße"},...]
查找POI的坐标
查找给定POI ID的坐标。
importdvbdvb.poi_coords(33000755)
{'lat':51.018745307424005,'lng':13.758700156062707}
坐标地址-WIP
查找给定坐标集的地址。
importdvblat=51.04373lng=13.70320dvb.address(lat,lng)
{'city':u'Dresden','address':u'Kesselsdorfer Straße 1'}
其他材料
查询中的停止名非常宽容。只要服务器看到它 作为一个独特的热门,它会起作用的。“helmholtzstra_e”找到的数据与 'Helmholtzstrasse'、'Nürnberger platz'='Nuernbergerplatz'等。
最后一个注意事项,确保不要运行你正在构建的 在图德累斯顿的网络里。调用dvb.route()和 dvb.find()将超时。不幸的是,这是预期的行为 来自这些IP范围的API调用被阻止。