def get_stoppoint(name): parameter = { 'searchString': name, 'maxResults': 5, 'searchTypes': 'STOPPOINT' } request = requests.get(baseurl.format(url_l), params=parameter) if request.status_code != 200: raise Exception if request.headers['content-type'] != 'application/json;charset=UTF-8': raise Exception data = request.json() resultstops = [] myask_log.debug(5, "got API request \n" + str(data) + "\n--------------") if data['resultCount'] == 0: myask_log.debug(3, u"No result for stop name {}".format(name)) elif data['resultCount'] > 1: myask_log.warning("More than one result for stop name '" + name + "' (" + str(data['resultCount']) + " found)") for elem in data['resultList']: stopid = elem['stopPointId'] stopname = unicodify(elem['stopPointName']) resultstops.append([stopid, stopname]) else: # a single result was shown stopid = data['resultList'][0]['stopPointId'] stopname = unicodify(data['resultList'][0]['stopPointName']) myask_log.debug( 3, u"Found a single match for '" + name + "': " + str(stopid) + " : " + stopname) resultstops.append([stopid, stopname]) return resultstops
def GetFilteredConnections(start_id, stop_id, preferred_bus, prefered_transport, utc_offset): if prefered_transport != "": myask_log.warning( u"GetFilteredConnections: Filtering by transport not yet implemented" ) return GetConnectionsWithBus(start_id, stop_id, preferred_bus, utc_offset)
def process_FindConnectionFromOther(slots, appdef, user_profile): #--------------------------------------------------------------------------- # Lists connections from a specific station to a specific station # # Intent: 'FindConnection' # Slots: # - "Origin" station to which connections should be found # - "OriginCity" # - "Destination" station to which connections should be found # - "DestinationCity" # "Busline" : list only buses for a specific line # "Next" : (future) List only next or next N connections # "Transport" : Filter by Mode of Transport: Bus, Train, Direct # Origin is set to the user's default sstation #--------------------------------------------------------------------------- myask_log.debug(3, "Got intent FindConnectionFromOther") # convert all times to localtime, independent of the AWS server location #----------------------------------------------------------------------- # get ID for origin stop #----------------------------------------------------------------------- if 'Origin' not in slots: if user_profile.isKnownUser(): # user favorite as fall-back slots['qorg_id'] = ToInt(user_profile.GetDefaultStopId()) else: return bus_response.out_OriginMissing(slots, appdef, user_profile) else: slots['qorg_id'] = ToInt(slots['Origin']) if slots['qorg_id'] < 10000: return bus_response.out_InvalidOrigin(slots['Origin'], slots, appdef, user_profile) #------------------------------------------------------------------------- # fill destination ID #------------------------------------------------------------------------- if 'Destination' in slots: destination_id = ToInt(slots["Destination"]) destination_str = slots["Destination"] elif 'qdest_id' in slots: # check if there is a station from the dialog context to re-use destination_id = ToInt(slots['qdest_id']) destination_str = "" else: # no information found. Use default location from user profile return bus_response.out_DestinationMissing(slots, appdef, user_profile) if int(destination_id) < 10000: myask_log.warning("Invalid stop id for destination station:" + str(destination_id)) return bus_response.out_InvalidDestination(destination_str, slots, appdef, user_profile) # we got a single result slots['qdest_id'] = destination_id return _FetchConnections(slots, appdef, user_profile)
def process_FindConnectionFromFavorite(slots, appdef, user_profile): #--------------------------------------------------------------------------- # Lists connections to a specific station from the user's default station # # Intent: 'FindConnectionFromFavorite' # Slots: # - "Destination" station to which connections should be found # - "DestinationCity" # "Busline" : list only buses for a specific line # "Next" : (future) List only next or next N connections # "Transport" : Filter by Mode of Transport: Bus, Train, Direct # Origin is set to the user's default sstation #--------------------------------------------------------------------------- myask_log.debug(3, "Got intent FindConnectionFromFavorite") #----------------------------------------------------------------------- # fill origin ID from user profile #----------------------------------------------------------------------- if user_profile.isKnownUser(): slots['qorg_id'] = ToInt(user_profile.GetDefaultStopId()) else: return bus_response.out_PromptUserProfileNeeded(slots) #------------------------------------------------------------------------- # fill destination ID #------------------------------------------------------------------------- if 'Destination' in slots: destination_id = ToInt(slots["Destination"]) destination_str = slots["Destination"] elif 'qdest_id' in slots: # check if there is a station from the dialog context to re-use destination_id = ToInt(slots['qdest_id']) destination_str = "" else: # no information found. Use default location from user profile return bus_response.out_DestinationMissing(slots, appdef, user_profile) myask_log.debug(5, "Got destination ID " + str(destination_id)) if int(destination_id) < 10000: myask_log.warning("Invalid stop id for destination station:" + str(destination_id)) if 'Destination.literal' in slots: return bus_response.out_InvalidDestination( slots["Destination.literal"], slots, appdef, user_profile) else: return bus_response.out_InvalidDestination(destination_str, slots, appdef, user_profile) # we got a single result slots['qdest_id'] = destination_id return _FetchConnections(slots, appdef, user_profile)
def __init__(self, userID): self._user_id = userID if userID == "FAKE": #Found profile of "diekellnerfamilie" self._profile_data = HARDCODED_PROFILES['TESTUSER'] else: self._profiletable = myask_dynamodb.dynamoDB("aseag_userprofile") myask_log.debug(0, "GetTable: " + str(self._profiletable.GetStatus())) profile_data = self._profiletable.FetchUserProfile(userID) if profile_data == {}: myask_log.warning( "Could not locate user profile. Creating new one. User: " + str(userID)) self._profiletable.CreateNewUserProfile(userID, {}) self._profile_data = {} else: self._profile_data = profile_data
def GetFavoriteConnection(self, favcon): #----------------------------------------------------------------------- # Gets favorite connection 'favcon' from the user profile # The favorite is a dictionary containing # "StartID" : (int) bus stop ID for starting stop # "StopID" : (int) bus stop ID for destination stop # "PreferredLines" : (list of integers) preferred buslines # "DepTimeWindowStart" : (time str) "07:15" # "DepTimeWindowEnd" : (time str) "07:35" # If 'favcon' is not found in the user profile, returns an empty dictionary {} #---------------------------------------------------------------------- if "FavoriteConnections" in self._profile_data: if favcon in self._profile_data["FavoriteConnections"]: fav = self._profile_data["FavoriteConnections"][favcon] return fav else: myask_log.warning("FavoriteConnection '" + favcon + "' not found for user" + self._profile_name) return {} else: myask_log.warning("No favorite connections found for user" + self._profile_name) return {}
def process_GetFavConnecionDepartures(slots, appdef, user_profile): #-------------------------------------------------------------------------- # shows departures a favorite connection from the uer's user profile # # Intent: 'GetFavConnecionDepartures' # Slot: 'FavConnection' identifier for a favorite connection from the user profile # A favorite connection (slot '') from the user profile provides # - departure station # - destination station # - preferred busline (optional) # - preferred time-window (optional) #-------------------------------------------------------------------------- myask_log.debug(3, "Got intent 'GetFavConnecionDepartures'") if 'FavConnection' not in slots: return bus_response.out_FavoriteConnectionMissing( slots, appdef, user_profile) else: fav_connection = user_profile.GetFavoriteConnection( slots["FavConnection"]) if len(fav_connection) == 0: return bus_response.out_FavoriteConnectionNotInUserProfile( slots["FavConnection"], slots, appdef, user_profile) else: # favorite connection found if "OrgID" not in fav_connection or "DestID" not in fav_connection: myask_log.warning( "No StartID or StopID found in FavoriteConnection '" + slots["FavConnection"] + "' for user ") return bus_response.out_InvalidFavoriteConnection( slots, appdef, user_profile) else: if "PreferredLines" in fav_connection: linefilter = fav_connection["PreferredLine"] else: linefilter = '' if "DepTimeWindowStart" in fav_connection: start_time = fav_connection["DepTimeWindowStart"] else: start_time = "" if "DepTimeWindowEnd" in fav_connection: end_time = fav_connection["DepTimeWindowEnd"] else: end_time = "" if 'utc_offset' in slots: utc_offset = slots['utc_offset'] else: utc_offset = 0 (match, result_connections) = aseag_api.FindFavoriteConnetions( fav_connection["OrgID"], fav_connection["DestID"], start_time, end_time, linefilter, utc_offset) # put it in the normal fields for smooth output slots['qorg_id'] = ToInt(fav_connection["OrgID"]) slots['qdest_id'] = ToInt(fav_connection["DestID"]) if linefilter != '': slots['Busline'] = str(linefilter) return bus_response.out_FavoriteConnection( match, result_connections, slots, appdef, user_profile) # if we are here, something went wrong return bus_response.out_ImplementationError( "process_GetFavConnecionDepartures", slots, appdef, user_profile)