实时BART(湾区快速交通)信息在您的终端!
pybart的Python项目详细描述
实时BART(Bay Area Rapid Transit)信息 在你的终端!
功能
- 实时评估和服务咨询
- Curses-based 自动刷新和调整大小的TUI
- 同时查看多个电台
- 表示公交线路、估计时间和列车长度的颜色
- 能够配置一组默认电台
- 其他非TUI命令,如打开地图并获取旅行费用
- 包括用于完整BART API的低级Python包装器
- 无依赖项;仅使用标准库构建
要求
- python 2.6+或python 3.0+,安装了curses模块(即 车窗)
- 支持256色的终端,以正确显示里士满弗里蒙特
线为橙色(否则为洋红色)
- 注意:这通常涉及将TERM环境变量设置为 xterm-256color
安装
pip install pybart
用法
usage: bart [-h] [-v] {map,list,est,fare} ... Display real time BART estimates. optional arguments: -h, --help show this help message and exit -v, --version show program's version number and exit commands: {map,list,est,fare} map open station map in web browser list show list of stations and their abbreviations est display estimates for specified stations fare show fare for a trip between two stations examples: bart get estimates for $BART_STATIONS bart map open station map bart list list all stations bart est mcar get estimates for MacArthur station bart est embr cols get estimates for Embarcadero and Coliseum stations bart fare conc sfia get fare for a trip between Concord and SFO stations
配置
以下(可选)环境变量可用于配置Pybart:
- BART_STATIONS-逗号分隔的字符串(例如mcar,embr,cols) 指定运行bart时要使用的默认工作站 论据。
- BART_API_KEY-获取信息时要使用的BART API密钥。一个 默认情况下使用public one,但您可以获得自己的 here。
API
尽管pybart并没有全部使用,但它包含了一个低级python 全套包装 BART API带 pybart.api.BART。默认情况下,每个调用都返回XML的根元素 使用响应 ElementTree。 json也受支持,但格式当前为 beta。
示例用法:
>>> from pybart.api import BART >>> bart = BART() # Uses the public API key by default >>> root = bart.stn.stninfo('dbrk') >>> station = root.find('stations').find('station') >>> print(station.find('address').text + ', ' + station.find('city').text) 2160 Shattuck Avenue, Berkeley >>> print(bart.version().find('apiVersion').text) 3.10 >>> bart = BART(json_format=True) # Now with JSON >>> root = bart.stn.stninfo('dbrk') >>> station = root['stations']['station'] >>> print(station['address'] + ', ' + station['city']) 2160 Shattuck Avenue, Berkeley