Esempio n. 1
0
def handle_text():
    data = request.form['Body']
    print "parsing:", data
    rt_code, stop_code = parse_rt_stop(data)

    if rt_code:
        rt_code = rt_code.lower()

        #Determine if rt_code is valid for currently running routes
        if bt_api.is_current_route(rt_code) == False:
            raise InvalidUsage("<Message>It looks like that bus route isn't currently running or is incorrect. You could try just sending the stop number to see all current routes at this location.</Message>")

        times = bt_api.get_next_departure_times_for_route_and_stop_code(routeShortName=rt_code, stopCode=stop_code)

        if times['success'] == False and times['error']:
            raise InvalidUsage("<Message>It looks like there are no buses currently running for that route and stop. You could try just sending the stop number to see all current routes at this location.</Message>")
            
        #times for route and stop code version doesn't have rt code embeded in it, so modify
        times['times'] = [(rt_code.upper(), [t]) for t in times['times']]
    else:
        times = bt_api.get_times_for_stop_code(stopCode=stop_code, requestShortNames=True)

    if times['success'] == False:
        raise InvalidUsage("""
            <Message>We're sorry, there was a problem retrieving stop times, please try again later.</Message>
        """)
    elif times['success'] == "Invalid":
        raise InvalidUsage("""
            <Message>That appears to be an invalid stop number, please try again.</Message>
        """)
    if times['times'] is None:
        raise InvalidUsage("""
            <Message>There are no current bus times for that stop number.</Message>
        """)

    message = ""

    for stop in times['times']:

        for time in stop[1]:
            dt = time.split()
            ft = dt[1][:-3]
            message += "{name} @ {time}{apm};\n".format(name=stop[0],time=ft, apm=dt[2].lower())

    reply = """<?xml version="1.0" encoding="UTF-8" ?>
            <Response>
            <Message>{content}</Message>
            </Response>""".format(content=message)
    return reply
Esempio n. 2
0
def handle_voice_input():
    try:
        data = request.form['Digits']
        rt_code = int(data)
    except:
        raise InvalidUsage("""
            <Gather timeout="15" finishOnKey="*" action="/voice" method="POST">
                <Say>Not a valid stop number, please try again.</Say>
            </Gather>
            <Gather timeout="15" finishOnKey="*" action="/voice" method="POST">
                <Say>Please enter the bus stop code and then press star.</Say>
            </Gather>
            <Say>We're sorry, we didn't receive any input. Goodbye!</Say>
            """)
    times = bt_api.get_times_for_stop_code(stopCode=rt_code, requestShortNames=False)
    
    if times['success'] is False:
        raise InvalidUsage("""
            <Say>We're sorry, there was a problem retrieving stop times, please try again later.</Say>
        """)
    elif times['success'] == "Invalid":
        raise InvalidUsage("""
            <Gather timeout="15" finishOnKey="*" action="/voice" method="POST">
                <Say>That appears to be an invalid stop number, please enter the stop number followed by the star key.</Say>
            </Gather>
            <Say>We're sorry, we didn't receive any input. Goodbye!</Say>
        """)
    if times['times'] is None:
        raise InvalidUsage("""
            <Say>There are no current bus times for that stop number. Goodbye!</Say>
        """)

    message = "The next bus arrival times are: "
    for stop in times['times']:
        for time in stop[1]:
            dt = time.split()
            ft = dt[1][:-3]
            message += "{name} at {time}{apm};".format(name=stop[0],time=ft, apm=dt[2].lower())

    reply = """<?xml version="1.0" encoding="UTF-8" ?>
            <Response>
                <Say>{content}. Thank you, goodbye!</Say>
            </Response>
            """.format(content=message)
    return reply
Esempio n. 3
0
def handle_text():
    try:
        data = request.form['Body']
        print "parsing:", data
        rt_code, stop_code = parse_rt_stop(data)
    except:
        raise InvalidUsage('<Message>Invalid stop number, please try again.</Message>')

    if rt_code:
        times = bt_api.get_next_departure_times_for_route_and_stop_code(routeShortName=rt_code, stopCode=stop_code)

        #times for route and stop code version doesn't have rt code embeded in it, so modify
        times['times'] = [(rt_code.upper(), [t]) for t in times['times']]
    else:
        times = bt_api.get_times_for_stop_code(stopCode=stop_code, requestShortNames=True)
    
    if times['success'] == False:
        raise InvalidUsage("""
            <Message>We're sorry, there was a problem retrieving stop times, please try again later.</Message>
        """)
    elif times['success'] == "Invalid":
        raise InvalidUsage("""
            <Message>That appears to be an invalid stop number, please try again.</Message>
        """)
    if times['times'] is None:
        raise InvalidUsage("""
            <Message>There are no current bus times for that stop number.</Message>
        """)

    message = ""
    
    for stop in times['times']:

        for time in stop[1]:
            dt = time.split()
            ft = dt[1][:-3]
            message += "{name} @ {time}{apm};\n".format(name=stop[0],time=ft, apm=dt[2].lower())

    reply = """<?xml version="1.0" encoding="UTF-8" ?>
            <Response>
            <Message>{content}</Message>
            </Response>""".format(content=message)
    return reply