Skip to content

Instantly share code, notes, and snippets.

@drwelby
Last active December 13, 2015 21:58
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 drwelby/4981013 to your computer and use it in GitHub Desktop.
Save drwelby/4981013 to your computer and use it in GitHub Desktop.

Curd Is The Word

[Cozy Cow Dairy] (http://www.cozycows.com) is the only source for [fresh cheese curds] (http://www.cozycows.com/products/cheese/) in the Colorado Front Range. If you're not from Wisconsin, the importance of freshness to cheese curds might not seem obvious. After all, cheese seems to stay perfectly fresh when kept cool, and some cheeses get better with age.

First, an explanation of what cheese curds are - consider them the caterpillar to a cheese butterfly. They're small chunks of coagulated milk that have been salted and cooked. Usually they are pressed together in molds and after some aging turn into solid blocks of cheese. In their curd form, they have a mild flavor and have a unique squeaky texture. They don't want to stay that way, however. They want to turn into cheese and the clock starts ticking as soon as they're made.

Fresh Cheese Curds

For real curd fans, it's essential to buy your curds as soon as they're ready. Originally, our customers asked us to send them text messages letting them know what time to come to the dairy to buy the freshest possible curds. At first we had a group list on a cell phone, then as the list got longer, a special group-texting iPhone app. Eventually we outgrew the app and needed a better solution. Our laundry list of features included:

  • Manage subscribers from a cell phone
  • Allow new subscribers to add or remove themselves
  • Send messages based on templates
  • Authorize multiple people to send messages

While there are companies that provide SMS marketing services, we didn't find exactly what we were looking for. But there are companies that provide voice and SMS platforms with easy to use APIs and client libraries. So we looked at rolling our own solution.

To handle the text messages, we use [Twilio] (http://www.twilio.com) which gives us a local number to work with. Incoming messages are converted to a http payload and can be posted to a specified URL. We can also send messages by posting a payload to their server. Their web interface makes configuration, debugging, and logging easy.

On our end, we needed a server to take the messages forwarded from Twilio and do something depending on their contents. Though many would say it's overkill, we wanted to use the Django framework due to familiarity and the built-in admin pages. Django takes the posted request, parses the message, and acts accordingly, either managing subscribers or sending out text messages.

We then needed a simple platform to host the Django app. Since we also have a dairy to run we needed something that required minimal setup. We also wanted something that was fast to update as we tweak what the alert system can do.

OpenShift was the perfect fit. At the free teir they still offer plenty of power to run a Django app with the bonus of not having to install and configure the full web server stack and DNS. The git-based deployment is easy and familiar, and their stock Django gear maintains a separate SQLite database so we automatically have a separate local development database. To test locally on your laptop, fire up Django's development server, open up a SSH tunnel (or use [Tunnlr] (http://www.tunnlr.com)) and point Twilio to the tunneled url. Test with your temporary number and local development database and when you're happy with the results just 'git push' to deploy and you're done.

OpenShift also supports pip-style library support, so you can add all sorts of third-party Python libraries. Since Twilio has their own library ready to go, sending and receiving messages gets reduced to one or two lines of code. All you have to do is add the libraries to a pip requirements.txt file in your local repo and they will be automatically installed upon deployment.

While simplicity is a benefit of a PAAS system like OpenShift, it can also limit what you can do. In our case, we also wanted to be able to send ourselves email updates so we could keep track of what messages were going in and out of the system. This functionality would seem to tip things towards using a full VPS, but there's even a simple solution for that. [Mailgun] (http://www.mailgun.com) works like Twilio does, but for emails. You can send emails by posting to their server, and there's a Django library to use Mailgun for its email backend. So by adding that library to pip's requirements.txt and changing a few Django settings, you have simple email functionality without having to set up a mail server.

In the end, we got a system that was easy to set up and did exactly what we wanted at a low cost. Our growing list of customers gets their curds when they're at their best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment