예제 #1
0
def ShowDepartureList(departure_list, slots, appdef):
    #--------------------------------------------------------------------------
    # displays information on bus departures
    # parameters:
    # - departure list
    # - slots: list of slots
    # - appdef: application definition (to (de-) canonicalize
    # Return (string): Multi-line card output
    #---------------------------------------------------------------------------
    if myask_slots.checkslots(slots, ['lang', 'qorg_id'],
                              "ShowDepartureList") == False:
        return myask_slots.error_slots_missing("ShowDepartureList")

    display_text = ""
    num_departures = len(departure_list)
    if num_departures == 0:
        display_text = u"Keine Abfahrten "
        display_text += u" ab " + appdef.GetSlotOutputName(
            "Origin", slots['qorg_id']) + u" (" + str(slots['qorg_id']) + u")"
        if 'Buslinie' in slots:
            display_text += u" für  Linie" + str(slots['Buslinie'])
        display_text += u" gefunden."
    else:
        display_text = str(num_departures) + u" Abfahrt(en)"
        display_text += u" ab " + appdef.GetSlotOutputName(
            "Origin", slots['qorg_id']) + u" (" + str(slots['qorg_id']) + u")"
        display_text += u" gefunden.\n"
        if num_departures > MAX_DISPLAY_CONNECTONS:
            num_departures = MAX_DISPLAY_CONNECTONS
            display_text += u"Hier sind die ersten " + str(
                num_departures) + u"\n"
        for i in range(num_departures):
            display_text += DisplayDeparture(departure_list[i], slots, appdef)

    return display_text
예제 #2
0
def DisplayConnectionList(connection_list, slots, appdef):
    if myask_slots.checkslots(slots, ['lang', 'qorg_id', 'qdest_id'],
                              "DisplayConnectionList") == False:
        return myask_slots.error_slots_missing("DisplayConnectionList")

    display_text = ""
    num_connections = len(connection_list)
    if num_connections == 0:
        display_text = "Keine Verbindung"
        display_text += " von " + appdef.GetSlotOutputName(
            "Origin", slots['qorg_id'])
        display_text += " nach " + appdef.GetSlotOutputName(
            "Destination", slots['qdest_id'])
        display_text += " gefunden."
    else:
        display_text = str(num_connections) + " Verbindungen"
        display_text += " von " + appdef.GetSlotOutputName(
            "Origin", slots['qorg_id'])
        display_text += " nach " + appdef.GetSlotOutputName(
            "Destination", slots['qdest_id'])
        display_text += " gefunden.\n"
        counter = 0
        for journey in connection_list:
            counter += 1
            display_text += str(counter) + ". : "
            display_text += DisplayJourneySimple(journey, slots, appdef)

    return display_text
예제 #3
0
def SpeakDeparturesList(departure_list, slots, appdef):
    # speak full information for  departures from  station qorg_id
    if myask_slots.checkslots(slots, ['lang', 'qorg_id'],
                              "SpeakDeparturesList") == False:
        return myask_slots.error_slots_missing("SpeakDeparturesList")

    speech_prompt = u""
    num_departures = len(departure_list)
    if num_departures == 0:
        speech_prompt = u"ich habe Keine Abfahrten "
        speech_prompt += u" ab " + appdef.GetSpokenSlotOutputName(
            "Origin", slots['qorg_id'])
        if "Direction" in slots:
            speech_prompt += u" Richtung " + appdef.GetSpokenSlotOutputName(
                "Direction", slots["Direction"])
        speech_prompt += u" gefunden.<break/>"
    elif num_departures == 1:
        speech_prompt = u"Ich habe folgende Abfahrt"
        speech_prompt += u" ab " + appdef.GetSpokenSlotOutputName(
            "Origin", slots['qorg_id'])
        if "Direction" in slots:
            speech_prompt += u" Richtung " + appdef.GetSpokenSlotOutputName(
                "Direction", slots["Direction"])
        speech_prompt += u" gefunden.<break/>"
        speech_prompt += SpeakDeparture(departure_list[0], slots, appdef)
    elif num_departures > MAX_CONNECTONS:
        speech_prompt += u"Hier sind die ersten " + str(MAX_CONNECTONS)
        speech_prompt += u" Abfahrten ab " + appdef.GetSpokenSlotOutputName(
            "Origin", slots['qorg_id'])
        if "Direction" in slots:
            speech_prompt += u" Richtung " + appdef.GetSpokenSlotOutputName(
                "Direction", slots["Direction"])
        speech_prompt += u".<break/>"
        for i in range(MAX_CONNECTONS):
            speech_prompt += SpeakDeparture(departure_list[i], slots, appdef)
    else:
        speech_prompt = u"Ich habe die folgenden Abfahrten"
        speech_prompt += u" ab " + appdef.GetSpokenSlotOutputName(
            "Origin", slots['qorg_id'])
        if "Direction" in slots:
            speech_prompt += u" Richtung " + appdef.GetSpokenSlotOutputName(
                "Direction", slots["Direction"])
        speech_prompt += u" gefunden.<break/>"
        for departure in departure_list:
            speech_prompt += SpeakDeparture(departure, slots, appdef)
    return speech_prompt
def _FetchConnections(slots, appdef, user_profile):
    #--------------------------------------------------------------------------
    # Finds connections from one bus stop to another
    #
    # Requires the following slots to be set:
    # 'qorg_id' bus stop ID for the origin stop
    # 'qdest_is' bus stop ID for the destination stop
    # Optional slots (used to filter the results=
    #    "Busline"  : list only this buses for a specific line
    #    "Next"      : (future) List only next or next N connections
    #    "Transport" : (future) Filter by Mode of Transport: Bus, Train, Direct
    # RETURNS: Alexa output structure
    #--------------------------------------------------------------------------

    if myask_slots.checkslots(slots, ['lang', 'qorg_id', 'qdest_id'],
                              "_FetchConnections") == False:
        return myask_alexaout.createAlexaErrorOutput(
            myask_slots.error_slots_missing("_FetchConnections"), slots)

    myask_log.debug(
        3, "In Function _FindConnection " + str(slots['qorg_id']) + "-->" +
        str(slots['qdest_id']))

    # prepare slots for call to aseag API

    # convert all times to localtime, independent of the AWS server location
    if 'utc_offset' in slots: utc_offset = slots['utc_offset']
    else: utc_offset = 0

    if 'Busline' in slots and slots['Busline'] != "?":
        linefilter = slots['Busline']
    else:
        linefilter = ''

    if 'Transport' in slots: transport = slots['Transport']
    else: transport = ""

    match, result_connections = aseag_api.GetFilteredConnections(
        slots['qorg_id'], slots['qdest_id'], linefilter, transport, utc_offset)

    myask_log.debug(2, "connection results from "+ str(slots['qorg_id'])+ " to " + str(slots['qdest_id'])+ \
                    "match:" +str(match)+":\n" + str(result_connections))

    return bus_response.out_Connections(result_connections, slots, appdef,
                                        user_profile)
예제 #5
0
def SpeakFavoriteConnections(match, connection_list, slots, appdef,
                             user_profile):
    if myask_slots.checkslots(slots, ['lang', 'qorg_id', 'qdest_id'],
                              "SpeakFavoriteConnections") == False:
        return myask_slots.error_slots_missing("SpeakFavoriteConnections")

    speech_output = ""
    num_connections = len(connection_list)
    if num_connections == 0:
        speech_output = u"Ich habe keine Verbindung"
        speech_output += u" von " + appdef.GetSpokenSlotOutputName(
            "Origin", slots['qorg_id'])
        speech_output += u" nach " + appdef.GetSpokenSlotOutputName(
            "Destination", slots['qdest_id'])
        speech_output += u" gefunden."
    elif match == False:
        speech_output = u"Ich habe die Lieblingsverbindung nicht gefunden. "
        speech_output += u"Hier sind Alternativen: <break/>"
        counter = 0
        for connection in connection_list:
            counter += 1
            speech_output += SpeakConnection(connection_list[0], slots, appdef)
    elif 'Buslines' in slots and len(slots['Buslines']) == 1:
        speech_output = u"Hier sind die gewünschen Lieblingsverbindungen "
        speech_output += u" mit der Linie " + str(slots['Buslines'][0])
        speech_output += u" von " + appdef.GetSpokenSlotOutputName(
            "Origin", slots['qorg_id'])
        speech_output += u" nach " + appdef.GetSpokenSlotOutputName(
            "Destination", slots['qdest_id'])
        speech_output += u":"
        counter = 0
        for connection in connection_list:
            counter += 1
            speech_output += SpeakConnectionDepArr(connection, slots, appdef)
            if counter == len(connection_list) - 1:
                speech_output += u" und "
    else:
        speech_output = u"Hier sind die gewünschen Lieblingsverbindungen: "
        counter = 0
        for connection in connection_list:
            counter += 1
            speech_output += SpeakShortConnection(connection, slots, appdef)

    return speech_output
def ConfirmChangeDefaultStation(slots, appdef, user_profile):
    #---------------------------------------------------------------------------
    # Handles confirmation of change of default slot
    # slot "Confirmed" contains the user answer
    #---------------------------------------------------------------------------
    if myask_slots.checkslots(slots, ['lang', 'Confirmed'],
                              "ConfirmChangeDefaultStation") == False:
        return myask_alexaout.createAlexaErrorOutput(
            myask_slots.error_slots_missing("ConfirmChangeDefaultStation"),
            slots)

    myask_log.debug(3, "Got command 'ConfirmChangeDefaultStation'")

    if "Origin" in slots:
        new_default_id = slots["Origin"]
    else:
        myask_log.error(
            "ConfirmChangeDefaultStation called without slot 'Origin'. How could this happen?"
        )
        new_default_id = user_profile.GetDefaultStopId()

    if slots["Confirmed"] == True:  # user confirmed
        myask_log.debug(5,
                        "User has confirmed selection of new default station")
        myask_log.debug(2, "New default station is " + str(new_default_id))
        result = user_profile.SetDefaultStopId(new_default_id)
        if result:
            myask_log.debug(1, "New favorite set successfully")
        else:
            myask_log.error("New favorite could not be set")
        return bus_response.out_DefaultChanged(slots, appdef, user_profile)
    else:  # user did not confirm
        return bus_response.out_DefaultChangeCancelled(slots, appdef,
                                                       user_profile)

    # if we are here, something went wrong
    return bus_response.out_ImplementationError(
        "process_GetFavConnecionDepartures", slots, appdef, user_profile)
예제 #7
0
def SpeakLineDepartures(departure_list, slots, appdef):
    # list departures of apsecific bus line from a specific busstop
    if myask_slots.checkslots(slots, ['lang', 'qorg_id', 'Busline'],
                              "SpeakLineDepartures") == False:
        return myask_slots.error_slots_missing("SpeakConnectionList")

    speech_prompt = u""
    numconnections = len(departure_list)
    if numconnections == 0:
        speech_prompt += u"ich habe Keine Abfahrten "
        speech_prompt += u"der Linie " + str(slots['Busline'])
        speech_prompt += u" ab " + appdef.GetSpokenSlotOutputName(
            "Origin", slots['qorg_id'])
        if "Direction" in slots:
            speech_prompt += u" " + appdef.GetSpokenSlotOutputName(
                "Direction", slots["Direction"])
        speech_prompt += u" gefunden.<break/>"
    else:
        speech_prompt += u"Die Linie " + str(slots['Busline'])
        speech_prompt += u" fährt ab " + appdef.GetSpokenSlotOutputName(
            "Origin", slots['qorg_id'])
        if "Direction" in slots:
            speech_prompt += u" " + appdef.GetSpokenSlotOutputName(
                "Direction", slots["Direction"])
        speech_prompt += u":"
    listcounter = 1
    if numconnections > MAX_CONNECTONS: numconnections = MAX_CONNECTONS
    for departure in departure_list:
        if listcounter > numconnections: break
        listcounter += 1
        (dep_time, busnr, destination) = departure
        speech_prompt += u" um " + dep_time.strftime('%H:%M')
        speech_prompt += u" richtung " + destination + u". <break/>"
        if listcounter == numconnections:
            speech_prompt += u" und "

    return speech_prompt
예제 #8
0
def SpeakConnectionList(connection_list, slots, appdef):
    if myask_slots.checkslots(slots, ['lang', 'qorg_id', 'qdest_id'],
                              "SpeakConnectionList") == False:
        return myask_slots.error_slots_missing("SpeakConnectionList")

    speech_output = ""
    num_connections = len(connection_list)
    if num_connections == 0:
        speech_output = u"Ich habe keine Verbindung"
        speech_output += u" von " + appdef.GetSpokenSlotOutputName(
            "Origin", slots['qorg_id'])
        speech_output += u" nach " + appdef.GetSpokenSlotOutputName(
            "Destination", slots['qdest_id'])
        speech_output += u" gefunden."
    elif num_connections == 1:
        speech_output = u"Ich habe die folgende Verbindung"
        speech_output += u" von " + appdef.GetSpokenSlotOutputName(
            "Origin", slots['qorg_id'])
        speech_output += u" nach " + appdef.GetSpokenSlotOutputName(
            "Destination", slots['qdest_id'])
        speech_output += u" gefunden.<break/>"
        speech_output += SpeakConnection(connection_list[0], slots, appdef)
    else:
        speech_output = u"Ich habe " + str(num_connections) + u" Verbindungen"
        speech_output += u" von " + appdef.GetSpokenSlotOutputName(
            "Origin", slots['qorg_id'])
        speech_output += u" nach " + appdef.GetSpokenSlotOutputName(
            "Destination", slots['qdest_id'])
        speech_output += u" gefunden.<break/>"
        counter = 0
        for connection in connection_list:
            counter += 1
            speech_output += str(counter) + u". Verbindung<break/> "
            speech_output += SpeakConnection(connection, slots, appdef)

    return speech_output