Documentation

main.py

main.add_followup_event_input(responsedata, output_params)[source]

Helper function for adding followupEventInput trigger to send data to queryHelper intent.

Parameters:
  • responsedata (dict) – The HTTP response data
  • output_params (dict) – Output context paramaters to send to queryHelper
main.cron_update()[source]

Google Cloud Platform scheduled CRON request handler. Checks for changes to MDining API data (Location/Meal), sends notification to Slack channel if change detected. Ignores changes to specified terms in ignore.json file. Authenticates requests by checking for user and passw in POST request body.

main.find_item(req_data)[source]
Dialogflow find_item intent handler.
Checks for valid Location and Item and sends HTTP response with appropriate data.
Parameters:req_data (dict) – Dialogflow POST request data
main.find_location_and_meal(req_data)[source]
Dialogflow find_location_and_meal intent handler.
Checks for valid Location and Meal and sends HTTP response with appropriate data.
Parameters:req_data (dict) – Dialogflow POST request data
main.home()[source]

Web app home page for quick successful deployment check.

main.is_partial_term(search, filename)[source]
Checks if input term is part of a larger official term by looking for any matches with
split up versions of regular terms.
Parameters:
  • search (string) – The searched term (e.g. ‘north quad’)
  • filename (string) – Name of the file the term is being searched for in (‘LocationExtra.txt’)
main.remove_ignore_entities(data, category)[source]
Removes entity terms to be ignored found in ignore.json
when comparing current local data and potentially updated MDining API data.
Parameters:
  • data (list) – List of items in current version of specified entity
  • category (string) – Entity category of the search term (‘Location’/’Meal’)
main.required_entities_handler(req_data, intentname)[source]
Handles response for intents with 2 or more entities that are required and
need to be handled manually, returns approriate parameters for specific intent handler to take care of. Will return list of entities in Data paramater of responsedata if all input parameters were valid, or a string response in the Data parameter containing response of issue to user.
Parameters:
  • req_data (dict) – The HTTP response data
  • intentname (string) – Output context paramaters to send to queryHelper
main.requisites_setup(requisites, input_params, output_params, additional_output_params)[source]
If any requisities specified in context parameters,
extracts them and adds them to output_params to remember for next query.
Parameters:
  • requisites (dict) – Contains information food item must comply with (traits, allergens, etc)
  • input_params (dict) – Input context paramaters containing user specifications
  • output_params (dict) – Output context paramaters to send to queryHelper
  • additional_output_params (dict) – Additional remembered context paramaters containing user specifications from previous query if needed
Handles user input that doesn’t match official terms exactly using is_partial_term.
If input search is a partial term of any official terms, returns list of recommended official terms.
Parameters:
  • search (string) – The searched term (e.g. ‘north quad’)
  • category – Entity category of the search term (‘Location’/’Meal’)
main.webhook_post()[source]

Dialogflow webhook POST Request handler requiring authentication. Uses find_location_and_meal or find_item intent handlers and returns appropriate JSON response.

datahandle.py

datahandle.check_course_available(data, course)[source]

Searches response data to check if course is available in specified meal.

Parameters:
  • data (dict) – MDining API HTTP response data
  • course (string) – Name of course
datahandle.check_item_specifications(item, traits, allergens)[source]

Returns true if food item is satisfactory with specified traits and allergens.

Parameters:
  • item (dict) – Data of specific food item
  • traits (list) – List of specified traits item must have, can be empty
  • allergens (list) – List of allergens item cannot have, can be empty
datahandle.check_meal_available(data, meal)[source]

Searches response data to check if meal is available at specified location/date.

Parameters:
  • data (dict) – MDining API HTTP response data
  • meal (string) – Name of meal
datahandle.find_item_formatting(possible_matches)[source]
Formatting list of possible matches into more natural sentence structure
by removing redundancy: [Chicken during lunch, chicken wings during lunch, and chicken patty during dinner] -> [Chicken, chicken wings during lunch, and chicken patty during dinner]
Parameters:possible_matches (list) – List of food items in data that matched user input
datahandle.find_matches(course_data, possible_matches, item_in, meal_name, requisites)[source]
Appends matches of specified food item in data of an individual course to
list of possible matches.
Parameters:
  • course_data (dict) – Chosen course subsection of MDining API HTTP response data
  • possible_matches (list) – List of food items in data that matched user input
  • item_in (string) – User input food item
  • meal_name (string) – Name of meal
  • requisites (dict) – Contains information food item must comply with (traits, allergens, etc)
datahandle.format_plural(text)[source]

Adds ‘and’ before last item in list of items.

Parameters:text (string) – The string to be manipulated
datahandle.format_requisites(text, requisites)[source]

If any item requisites specified, adds them to response text data for more holistic response.

Parameters:
  • text (string) – The response text data to be formatted
  • requisites (dict) – Contains information food item must comply with (traits, allergens, etc)
datahandle.get_items(data, requisites, formatted)[source]
Returns string of food items of each course in response data for
fulfillmentText in response to Dialogflow.
Parameters:
  • data (dict) – MDining API HTTP response data
  • requisites (dict) – Contains information food item must comply with (traits, allergens, etc)
  • formatted (boolean) – True/False - formats response string if true
datahandle.get_secrets()[source]

Fetches secrets from Datastore and returns them as a list.

datahandle.remove_spaces(url_block)[source]

Removes spaces in url string to create valid url string.

Parameters:url_block – The url string to be manipulated
datahandle.report_error(error_text)[source]

Logs error to Stackdriver. :param error_text: The text to log to Stackdriver :type error_text: string

datahandle.request_item(date_in, loc_in, item_in, meal_in, requisites)[source]
Handles searching for appropriate data response for valid specified
location and food item entities (and meal entity if included) from findItem intent.
Parameters:
  • date_in (string) – Input date
  • loc_in (string) – Input location
  • item_in (string) – Input food item
  • meal_in (string) – Input meal, can be empty string if not specified
  • requisites (dict) – Contains information food item must comply with (traits, allergens, etc)
datahandle.request_location_and_meal(date_in, loc_in, meal_in, requisites)[source]
Handles searching for appropriate data response for valid specified
location and meal entities from findLocationAndMeal intent.
Parameters:
  • date_in (string) – Input date
  • loc_in (string) – Input location
  • meal_in (string) – Input meal
  • requisites (dict) – Contains information food item must comply with (traits, allergens, etc)

remove_ignore_entities.py