Example #1
0
def get_s2s_data(msg):
    stations = BeijingBus.extract_stations(msg)
    if len(stations) < 2:
        output = '没有结果,可能还不支持这条线路呢~ \n%s' % QUERY_EXAMPLE
        return output

    from_station, to_station = stations[:2]
    lines = BeijingBus.extract_lines(msg)
    lines = match_stations_with_lines(from_station, to_station, lines)
    if not lines:
        output = '没有结果,可能还不支持这条线路呢~ \n%s' % QUERY_EXAMPLE
        return output

    output = get_realtime_message(lines, from_station)
    return output
Example #2
0
def query(**kwargs):
    username = kwargs.get('sender')
    sender = kwargs.get('receiver')
    message_type = kwargs.get('type')

    def r(content):
        return weixin.reply(username, sender=sender, content=content)

    if message_type == 'event' and kwargs.get('event') == 'subscribe':
        msg = app.config.get('ON_FOLLOW_MESSAGE')
        if not msg:
            return ''

        return weixin.reply(username,
                            type='news',
                            sender=sender,
                            articles=[msg])

    content = kwargs.get('content')
    if not content:
        reply = '我好笨笨哦,还不懂你在说什么。\n%s' % QUERY_EXAMPLE
        return r(reply)

    if isinstance(content, unicode):
        content = content.encode('utf-8')

    stations = BeijingBus.extract_stations(content)
    lines = BeijingBus.extract_lines(content)
    if len(stations) < 2:
        reply = '没有结果,可能还不支持这条线路呢~ \n%s' % QUERY_EXAMPLE
        return r(reply)

    from_station, to_station = stations[:2]
    lines = match_stations_with_lines(from_station, to_station, lines)
    if not lines:
        reply = '没有结果,可能还不支持这条线路呢~ \n%s' % QUERY_EXAMPLE
        return r(reply)

    reply = get_realtime_message(lines, from_station)
    return r(reply)
Example #3
0
def query(**kwargs):
    username = kwargs.get('sender')
    sender = kwargs.get('receiver')
    message_type = kwargs.get('type')

    def r(content):
        return weixin.reply(
            username, sender=sender, content=content
        )

    if message_type == 'event' and kwargs.get('event') == 'subscribe':
        reply = ('欢迎关注北京实时公交!\n'
                 '你可以通过向我发送消息查询公交实时到站时间。\n\n%s'
                ) % QUERY_EXAMPLE
        return r(reply)

    content = kwargs.get('content')
    if not content:
        reply = '我好笨笨哦,还不懂你在说什么。\n%s' % QUERY_EXAMPLE
        return r(reply)

    if isinstance(content, unicode):
        content = content.encode('utf-8')

    stations = BeijingBus.extract_stations(content)
    lines = BeijingBus.extract_lines(content)
    if len(stations) < 2:
        reply = '没有结果,可能还不支持这条线路呢~ \n%s' % QUERY_EXAMPLE
        return r(reply)

    from_station, to_station = stations[:2]
    lines = match_stations_with_lines(from_station, to_station, lines)
    if not lines:
        reply = '没有结果,可能还不支持这条线路呢~ \n%s' % QUERY_EXAMPLE
        return r(reply)

    reply = get_realtime_message(lines, from_station)
    return r(reply)
Example #4
0
def query(**kwargs):
    username = kwargs.get("sender")
    sender = kwargs.get("receiver")
    message_type = kwargs.get("type")

    def r(content):
        return weixin.reply(username, sender=sender, content=content)

    if message_type == "event" and kwargs.get("event") == "subscribe":
        msg = app.config.get("ON_FOLLOW_MESSAGE")
        if not msg:
            return ""

        return weixin.reply(username, type="news", sender=sender, articles=[msg])

    content = kwargs.get("content")
    if not content:
        reply = "我好笨笨哦,还不懂你在说什么。\n%s" % QUERY_EXAMPLE
        return r(reply)

    if isinstance(content, unicode):
        content = content.encode("utf-8")

    stations = BeijingBus.extract_stations(content)
    lines = BeijingBus.extract_lines(content)
    if len(stations) < 2:
        reply = "没有结果,可能还不支持这条线路呢~ \n%s" % QUERY_EXAMPLE
        return r(reply)

    from_station, to_station = stations[:2]
    lines = match_stations_with_lines(from_station, to_station, lines)
    if not lines:
        reply = "没有结果,可能还不支持这条线路呢~ \n%s" % QUERY_EXAMPLE
        return r(reply)

    reply = get_realtime_message(lines, from_station)
    return r(reply)