예제 #1
0
def query(**kwargs):
    username = kwargs.get('sender')
    sender = kwargs.get('receiver')
    message_type = kwargs.get('type')
    content = kwargs.get('content')
    if message_type == 'event' and kwargs.get('event') == 'subscribe':
        return weixin.reply(username, type='text', sender=sender, content=Tip_MESSAGE)
    if message_type != 'text' or (not content):
        return weixin.reply(username, sender=sender, content=ERROR_MESSAGE)
    cs = content.split('-')
    if len(cs) != 4:
        return weixin.reply(username, sender=sender, content=ERROR_MESSAGE)
    elif not cs[0] in app.config.get('DISTRICT'):
        reply = u"目前不支持此城市的查询"
        return weixin.reply(username, sender=sender, content=reply)
    cityname = app.config.get('DISTRICT')[cs[0]]
    cityid = BusTime.get_cities()[cityname]
    lineinfo = BusTime.get_line_infos(cs[1], cityid)
    if not lineinfo:
        reply = u'目前查询不到该线路的信息, 稍后试试呢'
        return weixin.reply(username, sender=sender, content=reply)
    elif lineinfo and isinstance(lineinfo, list):
        reply = u'亲 没找到呢。猜你想查找的是下面的线路id:\n' + '\n'.join([line['lineId'] for line in lineinfo])
        return weixin.reply(username, sender=sender, content=reply)

    lineid = '-'.join(cs[0:3])
    print lineid
    real_lineinfo = BusTime.get_real_line_infos(lineid, cityid)
    search_stop_name_or_id = cs[-1]
    reply_businfo = u'%s->%s\n首:%s  终:%s\n' % (real_lineinfo['startStopName'], real_lineinfo['endStopName'], real_lineinfo['firstTime'], real_lineinfo['lastTime'])
    reply_realtime_info = BusTime.get_bus_realtime(lineid, cityid, search_stop_name_or_id)
    if not reply_realtime_info:
        reply_realtime_info = u'获取不到实时公交信息, 稍后试试呢'
    print reply_businfo, reply_realtime_info
    reply = '%s  %s' % (reply_businfo, reply_realtime_info)
    return weixin.reply(username, sender=sender, content=reply)
예제 #2
0
# coding: utf-8
import click
from api.bustime import BusTime
from config import DISTRICT


if __name__ == '__main__':
    lineid = click.prompt(u'请输入线路id。格式为 "城市区号-线路号-0" 或者 "城市区号-线路号-1".\n1正向行使,0逆向行驶\n', value_proc=str)
    city = DISTRICT[lineid.split('-')[0]]
    search_stop_name_or_id = click.prompt(u'请输入需要查询的站点的名称或者在线路上的序号')
    city_dict = dict(BusTime.get_cities())
    cityid = city_dict[city]
    bustime_result = BusTime.get_bus_realtime(lineid, cityid, search_stop_name_or_id)
    print bustime_result
예제 #3
0
# coding: utf-8
import click
from api.bustime import BusTime
from config import DISTRICT

if __name__ == '__main__':
    lineid = click.prompt(
        u'请输入线路id。格式为 "城市区号-线路号-0" 或者 "城市区号-线路号-1".\n1正向行使,0逆向行驶\n',
        value_proc=str)
    city = DISTRICT[lineid.split('-')[0]]
    search_stop_name_or_id = click.prompt(u'请输入需要查询的站点的名称或者在线路上的序号')
    city_dict = dict(BusTime.get_cities())
    cityid = city_dict[city]
    bustime_result = BusTime.get_bus_realtime(lineid, cityid,
                                              search_stop_name_or_id)
    print bustime_result
예제 #4
0
# coding: utf-8
from api.bustime import BusTime

if __name__ == '__main__':
    # stop names in an line
    line_orders = BusTime.get_line_orders('022-610-0', '006')
    for _, stopname in iter(line_orders):
        print stopname
    print
    # cities
    cities = BusTime.get_cities()
    for city in cities:
        print u'城市=%s 城市id=%s' % (city, cities[city])
    print
    # line_infos
    # lineinfo = BusTime.get_line_infos('610', '006')
    lineinfo = BusTime.get_line_infos('611', '006')
    if lineinfo and isinstance(lineinfo, dict):
        print u'%s->%s\n首:%s  终:%s' % (lineinfo['startStopName'], lineinfo['endStopName'], lineinfo['firstTime'], lineinfo['lastTime'])
    elif lineinfo and isinstance(lineinfo, list):
        print u'亲 没找到呢。猜你想查找的是下面的线路:\n' + '\n'.join([line['lineId'] for line in lineinfo])
    else:
        print u'没有查到该线路相关信息'
    print
    # realtime bus
    # bus_realtime_result = BusTime.get_bus_realtime('022-633-0', '006', u'康桥里')
    # bus_realtime_result = BusTime.get_bus_realtime('022-633-0', '006', '22')
    bus_realtime_result = BusTime.get_bus_realtime('022-633-0', '006', 22)
    print bus_realtime_result
    print
    # 简单的返回按照站点搜索经过该站点的公交车情况
예제 #5
0
# coding: utf-8
from api.bustime import BusTime

if __name__ == '__main__':
    # stop names in an line
    line_orders = BusTime.get_line_orders('022-610-0', '006')
    for _, stopname in iter(line_orders):
        print stopname
    print
    # cities
    cities = BusTime.get_cities()
    for city in cities:
        print u'城市=%s 城市id=%s' % (city, cities[city])
    print
    # line_infos
    # lineinfo = BusTime.get_line_infos('610', '006')
    lineinfo = BusTime.get_line_infos('611', '006')
    if lineinfo and isinstance(lineinfo, dict):
        print u'%s->%s\n首:%s  终:%s' % (
            lineinfo['startStopName'], lineinfo['endStopName'],
            lineinfo['firstTime'], lineinfo['lastTime'])
    elif lineinfo and isinstance(lineinfo, list):
        print u'亲 没找到呢。猜你想查找的是下面的线路:\n' + '\n'.join(
            [line['lineId'] for line in lineinfo])
    else:
        print u'没有查到该线路相关信息'
    print
    # realtime bus
    # bus_realtime_result = BusTime.get_bus_realtime('022-633-0', '006', u'康桥里')
    # bus_realtime_result = BusTime.get_bus_realtime('022-633-0', '006', '22')
    bus_realtime_result = BusTime.get_bus_realtime('022-633-0', '006', 22)