Skip to content

Instantly share code, notes, and snippets.

@arthirad
Created July 13, 2016 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arthirad/79875e453f7092c3fc1c16782d5a9213 to your computer and use it in GitHub Desktop.
Save arthirad/79875e453f7092c3fc1c16782d5a9213 to your computer and use it in GitHub Desktop.
utils for my recipes, with functions, etc.
#!/usr/bin/python
import sys
import numpy as np
import random
def is_input_valid(question, input):
valid = {"yes": True, "y": True, "ye": True,
"no": False, "n": False}
if input is None:
prompt = " [yes/no] "
elif default == "yes":
prompt = " [Y/n] "
elif default == "no":
prompt = " [y/N] "
else:
raise ValueError("invalid default answer: '%s'" % input)
while True:
sys.stdout.write(question + prompt)
choice = raw_input().lower()
if input is not None and choice == '':
return valid[choice]
elif choice in valid:
return valid[choice]
else:
sys.stdout.write("Please respond with 'yes' or 'no' "
"(or 'y' or 'n').\n")
def is_meal_valid(question, prompt):
#for meal prompt = ['breakfast', 'lunch', 'dinner']
prompt_string = '/'.join(prompt)
if prompt is not None:
sys.stdout.write(question + ' [' + prompt_string + '] ')
choice = raw_input().lower()
if choice == '' or choice in prompt:
return choice
else:
sys.stdout.write("Please respond with %s \n" % ' or '.join(prompt))
return False
def print_current_pantry(current_pantry):
sys.stdout.write('Your current pantry includes: ')
sys.stdout.write(', '.join(current_pantry))
def make_breakfast(current_pantry, veggies):
#I like eggs the most! If I have eggs, then I want eggs, else, something else
if 'eggs' in current_pantry:
#eggs either scrambled OR omlette with 3 veggies
egg_style = random.choice(['scrambled', 'in an omlette'])
shuffled_veggies = randomize_veggies(veggies)
return 'Let\'s have our eggs %s with %s! Bon Apetit.' % (egg_style , shuffled_veggies)
elif 'bread' in current_pantry or 'potatoes' in current_pantry:
# toast with fruit or potatoes
return 'Let\'s have %s!' % (random.choice(['potatoes', 'toast with fruit']))
else:
return 'Looks like it\'s just you and that giant cup of coffee this morning...'
def make_lunch_or_dinner(carb, staples, current_pantry, veggies):
#My lunches and dinners generally have a carb and veggie component. Let's make that happen.
shuffled_veggies = randomize_veggies(veggies)
this_carb = random.choice(carb)
lunch_or_dinner = ''
if this_carb is 'bread':
lunch_or_dinner = 'We\'re going to make a sandwich with grilled %s ' % shuffled_veggies
if 'cheese' in current_pantry:
lunch_or_dinner = lunch_or_dinner + 'with cheese!'
elif 'ketchup' in current_pantry:
lunch_or_dinner = lunch_or_dinner + 'with ketchup!'
if this_carb is 'noodles':
noodle_style = random.choice(['yakisoba', 'ramen noodles'])
lunch_or_dinner = 'We\'re going to make %s with %s!' % (noodle_style, shuffled_veggies)
if this_carb is 'rice' or this_carb is 'quinoa':
grain_style = random.choice(['fried rice with soy/tamari', 'indian style sabji'])
lunch_or_dinner = 'We\'re going to make %s with %s!' % (grain_style, shuffled_veggies)
return lunch_or_dinner
def randomize_veggies(veggies):
np.random.shuffle(veggies)
return ', '.join(veggies[0:3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment