Exemplo n.º 1
0
        if restaurants[restaurant_name].fave >= score:
            print(restaurant_name + " is a " + str(restaurants[restaurant_name].fave) + "/5 rated place " + \
                  str(restaurants[restaurant_name].dist) + " minutes from here")



def add_restaurant():
    name = input("Enter Restaurant Name: ")
    cuisine = input("Enter Restaurant type: ")
    cost = input("Enter Restaurant cost (out of 5): ")
    fave = input("Enter star rating (out of 5): ")
    dist = input("Enter distance (minutes' walk): ")
    restaurants[name] = shared.Restaurant(name, cuisine, cost, fave, dist)


shared.read_csvfile(restaurants, filename)

print(restaurants)
while not finished:
    show_menu()
    choice = input("Please enter choice: ")
    if choice == "1":
        search_on_distance(input("Please enter max distance: "))
    elif choice == "2":
        search_on_rating(input("Please enter minimum rating: "))
    elif choice == "3":
        add_restaurant()
    elif choice == "4":
        shared.save_changes(restaurants, filename)
    elif choice == "5":
        finished = True
Exemplo n.º 2
0
    for restaurant_name in restaurants.keys():
        if restaurants[restaurant_name].fave >= score:
            print restaurant_name + " is a " + str(restaurants[restaurant_name].fave) + "/5 rated place " + \
                  str(restaurants[restaurant_name].dist) + " minutes from here"


def add_restaurant():
    name = raw_input("Enter Restaurant Name: ")
    cuisine = raw_input("Enter Restaurant type: ")
    cost = raw_input("Enter Restaurant cost (out of 5): ")
    fave = raw_input("Enter star rating (out of 5): ")
    dist = raw_input("Enter distance (minutes' walk): ")
    restaurants[name] = shared.Restaurant(name, cuisine, cost, fave, dist)


restaurants = shared.read_csvfile(filename)

while not finished:
    show_menu()
    choice = raw_input("Please enter choice: ")
    if choice == "1":
        search_on_distance(raw_input("Please enter max distance: "))
    elif choice == "2":
        search_on_rating(raw_input("Please enter minimum rating: "))
    elif choice == "3":
        add_restaurant()
    elif choice == "4":
        shared.save_changes(filename, restaurants)
    elif choice == "5":
        finished = True
    else:
Exemplo n.º 3
0
def add_restaurant():
    name = input("Enter Restaurant Name: ")
    cuisine = input("Enter Restaurant type: ")
    cost = input("Enter Restaurant cost (out of 5): ")
    fave = input("Enter cost (out of 5): ")
    dist = input("Enter distance (minutes' walk): ")
    restaurants[name] = {
        "type": cuisine,
        "cost": cost,
        "fave": fave,
        "dist": dist
    }


shared.read_csvfile(restaurants)

while not finished:
    show_menu()
    choice = input("Please enter choice: ")
    if choice == "1":
        search_on_distance(input("Please enter max distance: "))
    elif choice == "2":
        search_on_rating(input("Please enter minimum rating: "))
    elif choice == "3":
        add_restaurant()
    elif choice == "4":
        shared.save_changes(restaurants)
    elif choice == "5":
        finished = True
    else:
        name = input_data.name
        type = input_data.type
        # Add some code in here to add the input to the internal restaurants data
        # Then save it out (call the function to save the changes)
        # Then send the HTML for the new restaurant back, like for TripDeviser above
        return name, type


class Restaurants:
    def GET(self):
        print restaurants
        web.header('Content-Type', 'text/plain')
        return '\n'.join(sorted(restaurants.keys()))


class SpecificRestaurant:
    def GET(self, name):
        web.header('Content-Type', 'text/plain')
        return str(restaurants[name])


class Index:
    def GET(self):
        return "This is the index page"


restaurants = shared.read_csvfile('restaurants-lesson8.csv')
app = web.application(urls, globals())

if __name__ == "__main__":
    app.run()
@get('/restarants')
def all_restaurants(self):
    print(restaurants)
    response.set_header('Content-Type', 'text/plain')
    return '\n'.join(restaurants.keys())


@get('/restaurants/<restaurant>')
def specific_restaurant(restaurant):
    response.set_header('Content-Type', 'text/plain')
    return str(restaurants[restaurant])

@get('/hello/<name:re:[A-Z][a-z]*>')
def say_hello(name):
    return f"Why hello there, {name}"


@get('/score/<score>')
def restaurants_by_score (score):
    # check that the score provided is one of the digits 1-5
    # hint: use a regular expression match
    score = int (score)
    #  get the restaurants with a particular score
    return # those restaurants


restaurants = shared.read_csvfile('restaurants-lesson7.csv')

if __name__ == "__main__":
    run(host='localhost', port=8080)
Exemplo n.º 6
0
            print(restaurant_name + " is a " + rest_details["fave"] + "/5 rated place " +
                  str(rest_details["dist"]) + " minutes from here")


def add_restaurant():
    name = input("Enter Restaurant Name: ")
    cuisine = input("Enter Restaurant type: ")
    cost = input("Enter Restaurant cost (out of 5): ")
    fave = input("Enter star rating (out of 5): ")
    dist = input("Enter distance (minutes' walk): ")
    # Change this to use a Restaurant instead of a dictionary as well.
    restaurants[name] = {"type": cuisine, "cost": cost,
                         "fave": fave, "dist": dist}


shared.read_csvfile(restaurants)

while not finished:
    show_menu()
    choice = input("Please enter choice: ")
    if choice == "1":
        search_on_distance(input("Please enter max distance: "))
    elif choice == "2":
        search_on_rating(input("Please enter minimum rating: "))
    elif choice == "3":
        add_restaurant()
    elif choice == "4":
        shared.save_changes(restaurants)
    elif choice == "5":
        finished = True
    else:
    cost = request.forms.get('cost')
    fave = request.forms.get('fave')
    dist = request.forms.get('dist')
    restaurants[name] = shared.Restaurant(name, cuisine, cost, fave, dist)
    shared.save_changes(filename, restaurants)
    return generate_response(name)


def generate_html_rest_list():
    list_entry = '<li><a href="/tripdeviser/{0}">{0}</a></li>'
    html_output_fragment = ''
    for restaurant_name in sorted(restaurants):
        html_output_fragment = html_output_fragment + list_entry.format(restaurant_name)
    return html_output_fragment


def generate_response(name):
    with open("tripdeviser.html") as html_template:
        output_html = html_template.read()
    output_html = output_html.replace('{{RESTLIST}}', generate_html_rest_list())
    output_html = output_html.replace('{{PLACENAME}}', name)
    output_html = output_html.replace('{{PLACEDESCRIPTION}}', str(restaurants[name]))
    return output_html


if __name__ == "__main__":
    filename = 'restaurants-lesson8.csv'
    restaurants = shared.read_csvfile(filename)
    print(restaurants)
    run(host='localhost', port=8080)