module/cli从eptc网站检索阿雷格里港市的公共汽车时间表。
pypoabus的Python项目详细描述
皮波阿布斯
模块从EPTC网站检索阿雷格里港的公共汽车时刻表
- 按区域列出公交线路代码:北、南、东、公共(来自Carris公司)
- 按总线检索时间表
数据源:www.eptc.com.br
为什么要做这个项目?
目前,阿雷格里港市政厅没有提供API来获取有关公共汽车时刻表的官方信息。该项目旨在提供一个接口,将eptc网站上的官方在线信息转换为json表示。
安装
$ pip install pypoabus
或
$ pipenv install pypoabus
设置项目
这个项目使用Pipenv作为打包工具。
所以您可以运行:
# Installing dependencies
$ pipenv install
使用make
:
# Using the Makefile
$ make install
在虚拟环境中作为python模块安装
$ git clone https://github.com/jonathadv/py-poa-bus.git $ cd py-poa-bus/ $ pipenv install $ pipenv shell (py-poa-bus-owRTHeFi) $ ./setup.py install
用法
列出总线
>>>frompypoabusimportpypoabus>>>zone='south'>>>list_bus_lines=pypoabus.list_bus_lines(zone)>>>foriinlist_bus_lines:...print(i)...{"code":"210-14","name":"110 - RESTINGA NOVA VIA TRISTEZA"}{"code":"210-81","name":"1101 - RESTINGA NOVA VIA TRISTEZA/DOMINGOS E FERIADOS"}{"code":"210-46","name":"1102 - RESTINGA NOVA VIA TRISTEZA/BARRA SHOPPING"}{"code":"211-11","name":"111 - RESTINGA VELHA (TRISTEZA)"}{"code":"211-12","name":"1111 - RESTINGA VELHA(TRISTEZA)/SHOPPING"}{"code":"272-33","name":"1112 - HIPICA/TRISTEZA"}
get公交线路时刻表
>>>frompypoabusimportpypoabus>>>bus_line_code='281-1'>>>timetable=pypoabus.get_bus_timetable(bus_line_code)>>>timetable.code'2811'>>>timetable.name'CAMPO NOVO / MORRO AGUDO'>>>timetable.to_json()'{"code": "2811", "name": "CAMPO NOVO / MORRO AGUDO", "schedules": [{"direction": "BAIRRO/CENTRO", "schedule_day": "Dias Úteis", "timetable": ["05:30", "06:00", "06:30", "06:55", "07:25", "07:45", "09:00", "09:55", "10:35", "11:00", "11:35", "12:35", "13:30", "14:10", "14:40", "15:45", "16:25", "17:55", "19:10", "20:30", "21:30", "22:25"]}, {"direction": "BAIRRO/CENTRO", "schedule_day": "Sábados", "timetable": ["06:15", "06:55", "07:45", "08:30", "10:20", "11:20", "13:35", "14:25", "15:40", "16:55", "18:10", "19:25", "21:05", "22:45"]}, {"direction": "CENTRO/BAIRRO", "schedule_day": "Dias Úteis", "timetable": ["06:20", "06:50", "08:05", "08:25", "08:45", "10:00", "10:55", "11:35", "12:00", "12:35", "13:35", "14:30", "15:10", "15:40", "16:45", "17:25", "17:50", "18:45", "18:55", "20:00", "22:15", "23:10"]}, {"direction": "CENTRO/BAIRRO", "schedule_day": "Sábados", "timetable": ["07:05", "07:45", "08:35", "09:20", "10:05", "11:10", "12:10", "14:25", "15:15", "16:30", "20:15", "21:50", "23:30"]}]}'>>>
命令工具
这个工具允许用户访问pypoabus的一些特性,而无需编写新的模块或python脚本。它处理stdout
和stderr
消息,因此|
(管道)可用于将输出发送到另一个处理程序。
下面的示例使用jq
(https://stedolan.github.io/jq/)格式化json输出。
帮助
$ python -m pypoabus usage: pypoabus [-h][-l zone | -t line_code][-f format][-d] optional arguments: -h, --help show this help message and exit -l zone, --list zone List all line codes by zone: [north|south|east|public] -t line_code, --timetable line_code Line code like 281-1, 101-1, etc. -f format, --format format [json|table] -d, --debug-url Log the URL that pypoabus will call
示例
列出总线
$ python -m pypoabus -l south -f json | jq # jq is only a external tool to format json (not included) :D
{"list":[{"code":"210-14","name":"110 - RESTINGA NOVA VIA TRISTEZA"},{"code":"210-81","name":"1101 - RESTINGA NOVA VIA TRISTEZA/DOMINGOS E FERIADOS"},{"code":"210-46","name":"1102 - RESTINGA NOVA VIA TRISTEZA/BARRA SHOPPING"},{"code":"211-11","name":"111 - RESTINGA VELHA (TRISTEZA)"}}
$ python -m pypoabus -l south -f table # format output as table
┌───────────────────────────────┐ │ List of Bus lines (South) │ └───────────────────────────────┘ ┌────────┬────────────────────────────────────────────────────────┐ │ Code │ Name │ ├────────┼────────────────────────────────────────────────────────┤ │ 210-14 │ 110 - RESTINGA NOVA VIA TRISTEZA │ ├────────┼────────────────────────────────────────────────────────┤ │ 210-81 │ 1101 - RESTINGA NOVA VIA TRISTEZA/DOMINGOS E FERIADOS │ ├────────┼────────────────────────────────────────────────────────┤ │ 210-46 │ 1102 - RESTINGA NOVA VIA TRISTEZA/BARRA SHOPPING │ ├────────┼────────────────────────────────────────────────────────┤ │ 211-11 │ 111 - RESTINGA VELHA (TRISTEZA) │ ├────────┼────────────────────────────────────────────────────────┤ │ 211-12 │ 1111 - RESTINGA VELHA(TRISTEZA)/SHOPPING │ ├────────┼────────────────────────────────────────────────────────┤ │ 272-33 │ 1112 - HIPICA/TRISTEZA │ ├────────┼────────────────────────────────────────────────────────┤ │ 149-0 │ 149 - ICARAI │ ├────────┼────────────────────────────────────────────────────────┤
get公交线路时刻表
$ python -m pypoabus -t 281-81 -f json | jq # jq is only a external tool to format json (not included) :D
{"code":"R81","name":"RAPIDA CAMPO NOVO","schedules":[{"direction":"BAIRRO/CENTRO","schedule_day":"Dias Úteis","timetable":["06:25","06:45","07:05","07:25","07:40","08:00"]},{"direction":"CENTRO/BAIRRO","schedule_day":"Dias Úteis","timetable":["17:20","17:45","18:15"]}]}
$ python -m pypoabus -t 281-81 -f table ┌──────────────────────────────┐ │ R81 - RAPIDA CAMPO NOVO │ └──────────────────────────────┘ ┌BAIRRO/CENTRO─┐ │ Dias Úteis │ ├──────────────┤ │ 06:25 │ │ 06:45 │ │ 07:05 │ │ 07:25 │ │ 07:40 │ │ 08:00 │ └──────────────┘ ┌CENTRO/BAIRRO─┐ │ Dias Úteis │ ├──────────────┤ │ 17:20 │ │ 17:45 │ │ 18:15 │ └──────────────┘