Example #1
0
def main():
    url = input('Input URL: ')
    name = get_name(url)
    rf = fetcher.RecipeFetcher()
    recipe_data = parser.parse_recipe(rf.scrape_recipe(url))
    options = '\nOptions:\n1 Make it vegetarian\n2 Make it un-vegetarian\n3 Make it healthier\n4 Make it less healthy\n5 Double the amount\n6 Cut it by half\n7 To Thai style\n8 To Japanese style\n9 Change cooking method\n10 Input a new URL\n11 Print internal representation\n12 Exit\nInput your choice (a number): '
    print('====================')
    print(name)
    output_recipe(recipe_data)
    print('====================')
    choice = input(options)
    while choice != '12':
        if choice == '1':
            recipe_data = vegetarian_transform.to_vegetarian(recipe_data)
        elif choice == '2':
            recipe_data = vegetarian_transform.from_vegetarian(recipe_data)
        elif choice == '3':
            recipe_data = healthy_transform.to_healthy(recipe_data)
        elif choice == '4':
            recipe_data = healthy_transform.from_healthy(recipe_data)
        elif choice == '5':
            recipe_data = double_or_half.transform_amount(
                recipe_data, 'double')
        elif choice == '6':
            recipe_data = double_or_half.transform_amount(recipe_data, 'half')
        elif choice == '7':
            recipe_data = to_thai_cuisine.transform_to_thai(recipe_data)
        elif choice == '8':
            recipe_data = to_japanese_cuisine.transform_to_japanese(
                recipe_data)
        elif choice == '9':
            old_method = input('From (enter a method, e.g. bake): ')
            new_method = input('To (enter a method, e.g. fry): ')
            recipe_data = method_transform.to_new_method(
                recipe_data, old_method, new_method)
        elif choice == '10':
            url = input('Input URL: ')
            name = get_name(url)
            recipe_data = parser.parse_recipe(rf.scrape_recipe(url))
        elif choice == '11':
            print(recipe_data)
            choice = input(options)
            continue
        print('====================')
        print(name)
        output_recipe(recipe_data)
        print('====================')
        choice = input(options)
Example #2
0
def index():
    global socket_thread
    global speech_thread
    global recipe

    k_base = kb.KnowledgeBase()
    k_base.load()
    #url = "http://allrecipes.com/recipe/219173/simple-beef-pot-roast/"        # acquires URL from form.html
    url = request.form['url']
    # print "this is url from form " + url
    recipe_object = parser.parse_recipe(url, k_base)     # parse html with our parser
    recipe = recipe_object
    #
    # if speech_thread is None:
    #     eventlet.greenthread.spawn_after(2, demo_function, recipe_object, k_base, url)
    #     print "started speech thread"
        # speech_thread = Thread(target=demo_function)
        # speech_thread.daemon = False
        # speech_thread.spawn_after(5)


    print "Rendering Recipe Page"

    recipe_title = recipe_object.title
    recipe_yield = recipe_object.servings
    recipe_ingredients = recipe_object.ingredients
    recipe_instructions = recipe_object.instructions
    photo_url = recipe_object.photo_url

    return render_template('recipe-speech.html', html_title=recipe_title, html_yield=recipe_yield,
                           html_ingredients=recipe_ingredients, html_instructions=recipe_instructions, jsondata="", html_photo=photo_url)
Example #3
0
def demo_function(parsed_recipe, k_base, url):
    # with app.test_request_context('/recipe', method='POST', namespace = "/test"):
    # print "app context is: " + current_app.name
    preamble = False
    global recipe

    if parsed_recipe is not None:
        recipe = parsed_recipe
    else:
        print "Recipe object not found. Generating object."
        recipe = parser.parse_recipe(url, k_base)
    # speech_engine = speech_response.VoiceEngine()
    emit('saythis', {"data": "This is a recipe for: " + recipe.title})
    # speech_engine.say_this("This is a recipe for: " + recipe.title)
    if preamble:
        time.sleep(1)
        # speech_engine.say_this("The first step is: " + recipe.instructions[0])
        emit('saythis', {"data": "The first step is: " + recipe.instructions[0]})
        time.sleep(1)
        emit('saythis', {"data": "Say Computer, Computer, to get me to wake up"})
        # speech_engine.say_this("Say Computer, Computer, to get me to wake up")
        time.sleep(2)