import sqlite3
import collections
import itertools


def get_menu(campuses, dates):
    """
    Retrieve the menu on the given dates for the given campuses from the database.

    Args:
        campuses: The campuses for which the menu is retrieved.
        dates: The dates for which the menu is retrieved.

    Returns:
        A nested dictionary with as keys the requested dates and campuses, and for each of these possibilities a
        dictionary with as key the type of menu item and as values the menu content and the prices for students and
        staff.
    """
    conn = sqlite3.connect('menu.db')
    c = conn.cursor()

    menu = collections.defaultdict(dict)
    for date, campus in itertools.product(dates, campuses):
        c.execute('SELECT type, item, price_student, price_staff FROM menu WHERE date = ? AND campus = ?', (date, campus))
        for menu_type, menu_item, price_student, price_staff in c.fetchall():
            menu[(date, campus)][menu_type] = (menu_item, price_student, price_staff)

    return menu