liquorCabinet.py

Matt and I threw a party last week. Or, based on our guest attendance, Matt threw a party and one of my friends happened to be there. In any case, it was a good time. We had a competently stocked little bar, including all the basic liquors, triple sec, dry and sweet vermouth, fresh fruit for garnishes, etc. The problem became that I didn’t have a good way to come up with the complete menu of drinks we could make. Sure, there are apps where you can put in the ingredients you have on hand and it tells you what drinks you can make. The problem is that those usually (always, in my experience) come prepopulated with their own database of drinks, which inevitably includes random stuff you’ve never heard of or never make. They always include a ton of gimmicky drinks that exist in all of two bars. That was NOT for me. I wanted a way to figure out what drinks I could make out of a self-defined database, so I could weed out stupid drinks with extreme prejudice. Being “savvy,” I came up with a Python 2.7 command line script that allows you to do just that. The basic flow is as follows:

1) Put in all your drink ingredients. Each ingredient gets added via a command of the form “python liquorCabinet.py add <Ingredient>”

One important caveat is that when entering ingredients in this version, I assume that space is a delimiter. What does that mean for those readers who aren’t used to command lines? Basically, no spaces in your drink names. I fix this later when it outputs the drinks you can make, but for the purposes of adding ingredients and later drinks, you’ll need to put in an underscore character whenever you want to put a space. So, to add Sweet Vermouth, we’d type “python liquorCabinet.py add Sweet_Vermouth”
Simple, yet surprisingly time consuming!

2) Put in the drinks you want to add to your database. Each drink is added via a command of the form “python liquorCabinet.py drink <Drink_Name> <Ingredient_One>… <Ingredient_N>”

So, to put in a Cuba Libre, you’d type “python liquorCabinet.py drink Cuba_Libre Rum Coke Lime”

Notice that the same convention of using underscores instead of spaces holds! Additionally, ensure that your capitalization is the same. Light_Rum is not the same (from the script’s standpoint) as light_rum. Nor is it the same as Light Rum, Rum, Light_rum, etc. Basically, type shit the same way and everything will be gravy.

After you’ve done this step for both drinks and ingredients, the script will generate two files in the directory that you’re running the script from. Don’t delete these! They’re the databases of your drinks and ingredients. If you delete them, you’ll have to reenter everything. Wamp wamp.
Finally, type “python liquorCabinet.py out” to get an HTML page spit out into the same directory. This page contains all the drinks from your database that you have ingredients for! As an example, say I’ve only got three drinks in the database, and my liquor cabinet contains gin, tonic, vodka and lime. My drinks are Gin and Tonic, Vodka Tonic and Long Island Iced Tea. If I type the command, the page will reflect that I can make the Gin and Tonic and the Vodka Tonic, but not the Long Island. If I were to add the rest of ingredients in a Long Island, it would show all three drinks. Lastly, if I removed Tonic from the ingredients, Vodka Tonic and Gin and Tonic would not longer be on the page. Cool, right?!?

“But Dan, what if I run out of an ingredient or make a mistake in entering something and want to remove an ingredient or drink?” Got ya covered, hypothetical reader.

To remove a drink, the syntax is “python liquorCabinet.py removeDrink <Drink_Name>” To remove an ingredient, it’s “python liquorCabinet.py remove <ingredient>”

There are also two diagnostic functions. The cabinet argument prints out all the ingredients you’ve entered. The drinks argument prints out all the drinks.

Lastly, there’s a batchAdd command, which takes a filename as an argument. The file itself is a text file containing one drink per line. I’ve included my drink list as a base. It adds many of the drinks I learned in bartending school.

You’ll notice that the output list DOESN’T look like crap, which might/should come as a surprise to those of you who have heard me bitch about CSS and webtech in general. Sorry to not disappoint, but Matt did the final polish on the script, enabling it to look all fancy. Kudos to him! We set this up by putting my computer back in the bar and running the script in a network accessible folder. That way, I could remotely eighty-six ingredients, which would update the HTML file on the network. We then had a touchscreen set up for our guests to scroll through the menu with. Whenever I killed an ingredient, I’d update it on my computer and hit refresh on the menu computer. The whole thing is a tad crude, but I’ll probably continue working on it (I’ve got a few ideas in mind.) In the mean time, throw some tech at your next party and you’ll bring a bit of novelty to the proceedings. You can find a zip file with the script here.

Tags: , ,

About Dan Subak

I'm a Software Developer in Test at Microsoft, a passable marksman, hip-hop aficionado, connoisseur of beer and bourbon and every now and again I've been known to build a physical thing or two. This might just cover a few of those.

Leave a comment