def compile_ingredients(type, effect, extra_ingredient): time.sleep(2) os.system('clear') print('[rustling noises]') time.sleep(2) #We want the ingredients to be related to the type of recipe and the effect keywords = [] #first choose a type related keyword if type == "poison": keywords.append(random.choice(['venom','poison','toxin'])) elif type == "remedy": keywords.append(random.choice(['treatment','cure','medicine','drug'])) else: keywords.append(random.choice(['power','super','ability','improvement','boost',''])) #now remove stopwords from effect remove = stopwords.words('english') + list(string.punctuation) effect_tok = [i for i in word_tokenize(effect.lower()) if i not in remove] keywords = keywords + effect_tok # print(keywords) time.sleep(2) # os.system('clear') print('[cursing]') time.sleep(2) os.system('clear') #Retrieve extra ingredients and sort them into liquid and solid ingredient_list = [ing for (ing,num) in ingredients.get_ingredients(keywords)] #sort liquid and solid liquids = open('data/liquids.txt').read().split('\n')[:-1] choice_liq = list(set([ing for ing in ingredient_list if (ing in liquids)])) choice_sol = list(set([ing for ing in ingredient_list if not(ing in liquids)])) #there is a chance that not enough liquids have been found, so quick fix: if len(choice_liq)<2: choice_liq = choice_liq + ['aether','toothpaste'] if len(choice_sol)<2: choice_sol = choice_sol + ['bread','doll eyes'] time.sleep(2) # print('\nAHA! Found it! Here it is...\n') time.sleep(1) print('\n\n*********************\n') #call generate recipe function from recipe.py if extra_ingredient != 'none': print('A recipe for a '+ type +' that contains '+extra_ingredient+'!\n\n') recipe.generate_recipe([type],[effect], choice_sol, choice_liq, [extra_ingredient]) else: main_ing = [random.choice(['weirdly solid ice cream','the thing under your bed','socks','wool of a young sheep'])] recipe.generate_recipe([type],[effect], choice_sol, choice_liq, main_ing)
def main(barcode, num_countries=10): country = get_country(barcode) r = get_ingredients(barcode) if country == 'USA': origins = origins_us_list(r['ingredients']) if len(origins) > 0: origins.sort(ascending=False) origins = origins.iloc[:num_countries] origins = (origins/origins.sum()) else: origins = {} return r['product_name'], origins
from bake import bake_cake from batter import make_cake_batter from ingredients import get_ingredients ingredients = get_ingredients() batter = make_cake_batter(ingredients) cake_result = bake_cake(batter, 350, 45) print(cake_result)
def post(self, request, _format=None): # pylint: disable=unused-argument, no-self-use """ Sample post request function. """ # this builds up a list of already ordered items, so we can compare again it # to stop against duplicate items items_ordered = [] if '_FOOD_MENU_' in request.data['slots']: for food_item in request.data['slots']['_FOOD_MENU_']['values']: if food_item['resolved'] == 1: items_ordered.append(food_item['value']) if food_item['resolved'] == -1 and food_item['food_menu_dest'] != 'NULL': food_item['tokens'] = food_item['food_menu_dest'] if '_MISSING_ITEMS_' in request.data['slots']: request.data['slots'].pop('_MISSING_ITEMS_', None) missing_items = [] # ingredients_list logic if (request.data['state'] == 'ingredients_list'): calorie_count = 0 ingredients_list = [] if '_FOOD_MENU_' in request.data['slots']: for food_item in request.data['slots']['_FOOD_MENU_']['values']: if not (food_item['resolved'] == -1 and food_item['tokens'] in items_ordered): food_item['resolved'] = 1 food_item['value'] = food_item['tokens'] # magical API call food_item['ingredients'] = get_ingredients(food_item['tokens']) if food_item['ingredients'] == ['Sorry, that item is not on the menu']: missing_items.append(food_item['value']) if food_item['resolved'] == 1: # magical API call calories = get_calories(food_item['tokens']) if calories: calorie_count = calorie_count + calories # this creates a `_CALORIE_TOTAL_` slot for our response request.data['slots']['_CALORIE_TOTAL_'] = { 'type': "int", 'values': [ { "value": calorie_count, "tokens": calorie_count, "resolved": 1, } ] } # food_order logic if (request.data['state'] == 'food_order'): if '_FOOD_MENU_' in request.data['slots']: for food_item in request.data['slots']['_FOOD_MENU_']['values']: if 'resolved' in food_item and food_item['resolved'] == -1: if food_item['tokens'] not in items_ordered: food_item['resolved'] = 1 food_item['value'] = food_item['tokens'] # magical API call if not on_menu(food_item['value']): missing_items.append(food_item['value']) # this deals with the tokens we extracted that are not on the menu, and # creates a `_MISSING_ITEMS_` slot for our response if missing_items: for item in missing_items: for food_item in request.data['slots']['_FOOD_MENU_']['values']: if ('value' in food_item and food_item['value'] == item): request.data['slots']['_FOOD_MENU_']['values'].remove(food_item) break request.data['slots']['_MISSING_ITEMS_'] = { 'type': "list", 'values': [ { "value": missing_items, "tokens": missing_items, "resolved": 1, } ] } # return the business logic payload return Response(request.data)