Skip to content

Instantly share code, notes, and snippets.

@jkwok91
Last active February 27, 2016 10:16
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 jkwok91/132668793de78212832c to your computer and use it in GitHub Desktop.
Save jkwok91/132668793de78212832c to your computer and use it in GitHub Desktop.
i never use my goddamn wit.ai powered baking converter (it makes a lot of mistakes and i never made a proper UI), so i decided to just whip up some quick python raw_input shit so i can bake some goddamn muffins right now
units = ["cup","tbsp","tsp"]
# ingred are grams per 1 cup
ingred = {
"cinnamon": 124.8,
"flour": 125,
"bread flour": 125,
"whole wheat flour": 125,
"cake flour": 113.398,
"butter": 226.888,
"baking powder": 220.973,
"baking soda": 170.58,
"cocoa powder": 86.118,
"granulated sugar": 199.91,
"brown sugar": 212.621,
"sour cream": 226,
"kosher salt": 288
}
# this function could be cleaner im not gonna lie
def convert(requests, item, amt, metricUnit):
if ((item not in ingred) or (metricUnit not in units)):
return "i don't know"
result = amt * ingred[item]
if (metricUnit == "tsp"):
result /= 48.0
elif (metricUnit == "tbsp"):
result /= 16.0
conversion = "%.2fg" % result
requests.append(conversion+" of "+item)
return conversion
def parseRequest(req,requests):
requestTokens = req.split(" ")
amount = float(requestTokens[0])
unit = requestTokens[1]
item = " ".join(requestTokens[2:])
return convert(requests, item, amount, unit)
def main():
requests = []
print("Welcome to the handy baking converter.")
print("Please input your request in the format [AMOUNT] [METRIC UNIT] [ITEM]. Thanks!")
print("Enter to quit")
req = raw_input("What do you need in grams? ")
while (req != ""):
print(parseRequest(req,requests))
req = raw_input("What do you need in grams? ")
print("Okay! Happy baking! Here are your requests:")
print("\n".join(requests))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment