维多利亚公共交通(PTV)的API包装

ptv-python-wrapper的Python项目详细描述


公共交通维多利亚(PTV)Python API包装器

Python3公共交通维多利亚API包装(https://www.ptv.vic.gov.au/

有关完整的api文档以及如何请求api密钥的信息,请查看ptvDocumentationSwagger

安装

$ pip install ptv-python-wrapper

用法

通过从ptv传入开发人员id和api密钥来实例化客户机

from ptv.client import PTVClient

client = PTVClient(DEV_ID, API_KEY)

从车站出发

从车站出发观看

Parameters
----------
route_type : integer
    Number identifying transport mode; values returned via RouteTypes API
stop_id : integer
    Identifier of stop; values returned by Stops API

Optional Parameters
-------------------
route_id : string
    Identifier of route; values returned by RoutesAPI - v3/routes
platform_numbers : Array[integer]
    Filter by platform number at stop
direction_id : integer
    Filter by indentifier of direction of travel; values returned by Directions Api - /v3/directions/route/{route_id}
look_backwards : boolean
    Indicates if filtering runs (and their departures) to those that arrive at destination before date_utc (default = false). Requires max_results > 0.
gtfs : boolean
    Indicates that stop_id parameter will accept "GTFS stop_id" data
date_utc : string
    Filter by the date and time of the request (ISO 8601 UTC format) (default = current date and time)
max_results : integer
    Maximum number of results returned
include_cancelled : boolean
    Indicates if cancelled services (if they exist) are returned (default = false) - metropolitan train only
expand : Array[string]
    List objects to be returned in full (i.e. expanded) - options include: all, stop, route, run, direction, disruption

Returns
-------
Departures : dict
    Dictionary of departures

示例:

client.get_departure_from_stop(0, 1071)

获取路线

的方向

查看路线方向

Parameters
----------
route_id : int
    Identifier of route; values returned by Routes API - v3/routes

Optional Parameters
-------------------
route_type : int
    Number identifying transport mode; values returned via RouteTypes API

Returns
-------
Directions : dict
    Dictionary of directions

示例:

client.get_directions_for_route(1)

获取方向

的路线

查看方向的路线

Parameters
----------
direction_id : int
    Identifier of direction of travel; values returned by Directions API - /v3/directions/route/{route_id}

Returns
-------
Routes : dict
    All routes that travel in the specified direction.

示例:

client.get_route_for_direction(1)

中断

查看所有中断

Optional Parameters
-------------------
route_id : int
    Identifier of route; values returned by Routes API - v3/routes
stop_id : int            	
    Identifier of stop; values returned by Stops API - v3/stops
disruption_status : str
    Filter by status of disruption

Returns
-------
disruptions : dict
    All disruption information (if any exists).

示例

client.get_disruptions()

查看特定中断

查看特定的中断

Parameters
----------
disruption_id : int
    Identifier of disruption; values returned by Disruptions API - /v3/disruptions OR /v3/disruptions/route/{route_id}

Returns
-------
disruptions : dict
    Disruption information for the specified disruption ID.

示例

client.get_disruption(12345)

获取所有中断模式

获取所有中断模式

Returns
-------
modes : dict
    Disruption specific modes

示例

client.get_disruption_modes()

列出售票点

列出售票点

Optional Parameters
-------------------
latitude : int
    Geographic coordinate of latitude
longitude : int
    Geographic coordinate of longitude
max_distance : int
    Maximum number of results returned 
max_results : int
    Maximum number of results returned (default = 30)

Returns
-------
outlets : dict
    Ticket outlets

示例

client.get_outlets()

查看特定行程/服务运行的停止模式

查看特定行程/服务运行的停止模式

Parameters
----------
run_id : int
    Identifier of a trip/service run; values returned by Runs API - /v3/route/{route_id} and Departures API
route_type : int
    Number identifying transport mode; values returned via RouteTypes API
expand : Array[str]
    Objects to be returned in full (i.e. expanded) - options include: all, stop, route, run, direction, disruption. By default disruptions are expanded.

Optional Parameters
-------------------
stop_id : int
    Filter by stop_id; values returned by Stops API
date_utc : str
    Filter by the date and time of the request (ISO 8601 UTC format)

Returns
-------
pattern : dict
    The stopping pattern of the specified trip/service run and route type.

示例

client.get(12345, 0, ['all'])

查看所有路线的路线名称和编号

查看所有路线的路线名称和编号

Optional Parameters
-------------------
route_types : Array[int]
    Filter by route_type; values returned via RouteTypes API
route_name : str
    Filter by name of route (accepts partial route name matches)

Returns
-------
routes : dict
    Route names and numbers for all routes of all route types.

示例

client.get_routes()

查看特定路线ID

的路线名称和编号

查看特定路线ID的路线名称和编号

Parameters
----------
route_id : int
    Identifier of route; values returned by Departures, Directions and Disruptions APIs

Returns
-------
route : dict
    The route name and number for the specified route ID.

示例

client.get_route(1)

查看所有路由类型及其名称

查看所有路线类型及其名称

Returns
-------
RouteTypes : dict
    All route types (i.e. identifiers of transport modes) and their names.

示例

client.get_route_types()

查看特定运行ID和路径类型的行程/服务

查看特定跑步ID和路线类型的行程/服务

Parameters
----------
run_id : int
    Identifier of a trip/service run; values returned by Runs API - /v3/route/{route_id} and Departures API

Optional Parameters
-------------------
route_type : int
    Number identifying transport mode; values returned via RouteTypes API

Returns
-------
run : dict
    The trip/service run details for the run ID and route type specified.

示例

client.get_run(12345, 0)

查看特定路线ID

的所有行程/服务运行

查看特定路线ID的所有行程/服务运行

Parameters
----------
route_id : int
    Identifier of route; values returned by Routes API - v3/routes.

Optional Parameters
-------------------
route_type : int
    Number identifying transport mode; values returned via RouteTypes API

Returns
-------
runs : dict
    All trip/service run details for the specified route ID.

示例

client.get_runs_for_route(1)

查看与搜索词匹配的站点、路线和Myki出口

查看与搜索词匹配的站点、路线和Myki出口

Parameters
----------
search_term : str
    Search text (note: if search text is numeric and/or less than 3 characters, the API will only return routes)

Optional Parameters
-------------------
route_types : Array[int]
    Filter by route_type; values returned via RouteTypes API (note: stops and routes are ordered by route_types specified)
latitude : float
    Filter by geographic coordinate of latitude
longitude : float
    Filter by geographic coordinate of longitude
max_distance : float
    Filter by maximum distance (in metres) from location specified via latitude and longitude parameters
include_addresses : bool
    Placeholder for future development; currently unavailable
include_outlets : bool
    Indicates if outlets will be returned in response (default = true)
match_stop_by_suburb : bool
    Indicates whether to find stops by suburbs in the search term (default = true)
match_route_by_suburb : bool
    Indicates whether to find routes by suburbs in the search term (default = true)
match_stop_by_gtfs_stop_id : bool
    Indicates whether to search for stops according to a metlink stop ID (default = false)

Returns
-------
SearchResponse : dict
    Stops, routes and myki ticket outlets that contain the search term (note: stops and routes are ordered by route_type by default).

示例

client.search('asdf')

查看特定站点的设施(仅限地铁站和V/线路站)

查看特定站点的设施(仅限地铁站和V/线路站)

Parameters
----------
stop_id : int
    Identifier of stop; values returned by Stops API
route_type : int
    Number identifying transport mode; values returned via RouteTypes API

Optional Parameters
-------------------
stop_location : bool
    Indicates if stop location information will be returned (default = false)
stop_amenities : bool  
    Indicates if stop amenity information will be returned (default = false)
stop_accessibility : bool
    Indicates if stop accessibility information will be returned (default = false)
stop_contact : bool
    Indicates if stop contact information will be returned (default = false)
stop_ticket : bool
    Indicates if stop ticket information will be returned (default = false)
gtfs : bool
    Incdicates whether the stop_id is a GTFS ID or not
stop_staffing : bool
    Indicates if stop staffing information will be returned (default = false)
stop_disruptions : bool
    Indicates if stop disruption information will be returned (default = false)

Returns
-------
Stop : dict
    Stop location, amenity and accessibility facility information for the specified stop (metropolitan and V/Line stations only).

示例

client.get_stop(1071, 0)

查看特定路线上的所有站点

查看特定路线上的所有站点

Parameters
----------
route_id : int
    Identifier of route; values returned by Routes API - v3/routes
route_type : int
    Number identifying transport mode; values returned via RouteTypes API

Optional Parameters
-------------------
direction_id : int
    An optional direction; values returned by Directions API. When this is set, stop sequence information is returned in the response.
stop_disruptions : bool
    Indicates if stop disruption information will be returned (default = false)

Returns
-------
stops : dict
    All stops on the specified route.

示例

client.get_stops_for_route(1, 0)

查看特定位置附近的所有站点

查看特定位置附近的所有站点

Parameters
----------
latitude : float
    Geographic coordinate of latitude
longitude : float
    Geographic coordinate of longitude

Optional Parameters
-------------------
route_types : Array[int]
    Filter by route_type; values returned via RouteTypes API
max_results : int
    Maximum number of results returned (default = 30)
max_distance : double  
    Filter by maximum distance (in metres) from location specified via latitude and longitude parameters (default = 300)
stop_disruptions : bool
    Indicates if stop disruption information will be returned (default = false)

Returns
-------
stops : dict
    All stops near the specified location.

示例

client.get_stops_for_location(123,123)

贡献

如果您发现了一个bug或想要一个新功能,请打开一个问题或创建一个拉取请求。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在构造函数外部添加鼠标侦听器   java如何使用比较器对列表进行排序以正确排序空值?   javajavax。由于javax,邮件“535.7.3身份验证失败”。邮件升级(v1.3.1至v1.5.2)   java将arraylist流到固定的二维数组中并打印?   RecyclerView适配器上的java上下文   java如何为此Twitter API为KafkaProducer建立连接   java Spring安全性重写WebSecurity配置适配器的配置(AuthenticationManagerBuilder)是否会影响全局应用程序?   线程“awteventque0”NullPointerException中的java异常   if条件中的null值和null指针异常java   java树集<Object>允许相同类型的多个对象   java定义类;我认不出   字符串java replaceAll()   JAVAutil。scanner(Java)读取文件时如何跳过空格?   java在swing中关闭flash屏幕   java在Wildfly 16中的应用程序中加载pk12文件   有没有工具可以自动生成屏幕抓取的Java代码   创建意图时,java方法getParcelableExtra()返回null   将数据从java传递到jsp   java Android Studio |永久保存布局