Giter VIP home page Giter VIP logo

beijing_bus's Introduction

[不再维护] 代码已经很久没有更新,调用的 api 接口可能已经改变。有兴趣的朋友可以提 PR

北京实时公交

该项目是北京实时公交查询接口的Python绑定,接口逆向自其安卓客户端

警告

此项目通过调用非公开接口获取数据,use at your own risk.

Quick Start

  • pip install -r requirements.txt 安装依赖
  • python manage.py build_cache 获取离线数据,建立本地缓存

项目自带了一个终端中的查询工具作为例子,运行: python manage.py cli

Examples

>>> from beijing_bus import BeijingBus
>>> lines = BeijingBus.get_all_lines()
>>> lines
[<Line: 运通122(农业展览馆-华纺易城公交场站)>, <Line: 运通101(广顺南大街北口-蓝龙家园)>, ...]
>>> lines = BeijingBus.search_lines('847')
>>> lines
[<Line: 847(马甸桥西-雷庄村)>, <Line: 847(雷庄村-马甸桥西)>]
>>> line = lines[0]
>>> print line.id, line.name
541 847(马甸桥西-雷庄村)
>>> line.stations
[<Station 马甸桥西>, <Station 马甸桥东>, <Station 安华桥西>, ...]
>>> station = line.stations[0]
>>> print station.name, station.lat, station.lon
马甸桥西 39.967721 116.372921
>>> line.get_realtime_data(1) # 参数为站点的序号,从1开始
[
    {
        'id': 公交车id,
        'lat': 公交车的位置,
        'lon': 公交车位置,
        'next_station_name': 下一站的名字,
        'next_station_num': 下一站的序号,
        'next_station_distance': 离下一站的距离,
        'next_station_arriving_time': 预计到达下一站的时间,
        'station_distance': 离本站的距离,
        'station_arriving_time': 预计到达本站的时间,
    },
    ...
]

Roadmap

  • 实现 beijing_bus 模块,提供需要的Python接口
  • 终端中的查询工具
  • 微信公众号,扫描二维码关注:

公众号二维码

beijing_bus's People

Contributors

wong2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

beijing_bus's Issues

更自然的查询方式

从微信后台看,很多用户都会直接输入 车次 进行查询,这也比较自然,需要想一想如何支持这种查询方式

好像不好用了

>>> from beijing_bus import BeijingBus
>>> lines = BeijingBus.get_all_lines()


然后,就没有然后了。hang 在那里了

先忽略---我研究一下

仓库中本地缓存的格式问题

现无法执行(gdbm.error: Bad magic number),会不会是依赖项目的版本问题,毕竟已经时隔十个月

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:        14.04
Codename:       trusty
>>> lines = BeijingBus.get_all_lines()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "beijing_bus/__init__.py", line 13, in get_all_lines
    return BusLine.get_all_lines()
  File "beijing_bus/line.py", line 73, in get_all_lines
    line_ids = cls.get_all_line_ids()
  File "/usr/local/lib/python2.7/dist-packages/dogpile/cache/region.py", line 1053, in decorate
    should_cache_fn)
  File "/usr/local/lib/python2.7/dist-packages/dogpile/cache/region.py", line 657, in get_or_create
    async_creator) as value:
  File "/usr/local/lib/python2.7/dist-packages/dogpile/lock.py", line 154, in __enter__
    return self._enter()
  File "/usr/local/lib/python2.7/dist-packages/dogpile/lock.py", line 87, in _enter
    value = value_fn()
  File "/usr/local/lib/python2.7/dist-packages/dogpile/cache/region.py", line 610, in get_value
    value = self.backend.get(key)
  File "/usr/local/lib/python2.7/dist-packages/dogpile/cache/backends/file.py", line 220, in get
    with self._dbm_file(False) as dbm:
  File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/usr/local/lib/python2.7/dist-packages/dogpile/cache/backends/file.py", line 215, in _dbm_file
    "w" if write else "r")
  File "/usr/lib/python2.7/anydbm.py", line 85, in open
    return mod.open(file, flag, mode)
gdbm.error: Bad magic number
>>> lines = BeijingBus.get_all_lines()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/justin/beijing_bus/beijing_bus/__init__.py", line 13, in get_all_lines
    return BusLine.get_all_lines()
  File "/home/justin/beijing_bus/beijing_bus/line.py", line 73, in get_all_lines
    line_ids = cls.get_all_line_ids()
  File "/usr/local/lib/python3.4/dist-packages/dogpile/cache/region.py", line 1053, in decorate
    should_cache_fn)
  File "/usr/local/lib/python3.4/dist-packages/dogpile/cache/region.py", line 657, in get_or_create
    async_creator) as value:
  File "/usr/local/lib/python3.4/dist-packages/dogpile/lock.py", line 154, in __enter__
    return self._enter()
  File "/usr/local/lib/python3.4/dist-packages/dogpile/lock.py", line 87, in _enter
    value = value_fn()
  File "/usr/local/lib/python3.4/dist-packages/dogpile/cache/region.py", line 610, in get_value
    value = self.backend.get(key)
  File "/usr/local/lib/python3.4/dist-packages/dogpile/cache/backends/file.py", line 220, in get
    with self._dbm_file(False) as dbm:
  File "/usr/lib/python3.4/contextlib.py", line 59, in __enter__
    return next(self.gen)
  File "/usr/local/lib/python3.4/dist-packages/dogpile/cache/backends/file.py", line 215, in _dbm_file
    "w" if write else "r")
  File "/usr/lib/python3.4/dbm/__init__.py", line 94, in open
    return mod.open(file, flag, mode)
_gdbm.error: Bad magic number

不能使用

python2.7
python manage.py build_cache失败
File "/Users/play/.py2/lib/python2.7/site-packages/dogpile/cache/region.py", line 610, in get_value
value = self.backend.get(key)
File "/Users/play/.py2/lib/python2.7/site-packages/dogpile/cache/backends/file.py", line 230, in get
value = compat.pickle.loads(value)
ValueError: unsupported pickle protocol: 4

是不是北京公交官方改了接口?
微信公众号,也不能使用。路线没有更新。

用不了,求解决

运行 python manage.py build_cache
会报错, 'NoneType' object is not subscriptable
作者你真的自己试用过吗.......

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.