Coffee Order
DESCRIPTION
We were hosting an event where a barista was hired to make coffee for our guests. As a convenience, my wife came up with an idea to use a receipt printer we had to generate orders for the barista and allow guests to order on an app.
After spending some time experimenting with Google Forms and the email automation that comes with it, I ended up writing my own form hosted on this site. The submissions are stored in files on the filesystem and order numbers generated with a counter stored in Redis. While this part is pretty straight forward, there is a print action involved that required a hardware piece that needed to be integrated.
Mac has an application called Automator that has a graphical interface providing the ability to string together known actions into a workflow. I ended up using a “Folder Action” which listens to new files being added to a folder and feeding that to a print action. Now we just needed to get the files from the form submission folder on the server to this folder on the Mac. To accomplish this quickly, I wrote a quick Python script that just polls with a “scp” command against the server and drops any new files into the folder being watched by the Automator.
The part that really sunk my time was the actual printed result that showed up on the paper. The Automator just opens the file in the associated format and issues a print command from that application. Initially, I was just writing .txt files and this forced the TextEdit app to open and print which had no notion of font size. The result was unreadable. My workaround was to write HTML files with CSS to style the text then associate the .html extension with TextEdit, thus styling the text before printing. This produced the desired results.
After spending some time experimenting with Google Forms and the email automation that comes with it, I ended up writing my own form hosted on this site. The submissions are stored in files on the filesystem and order numbers generated with a counter stored in Redis. While this part is pretty straight forward, there is a print action involved that required a hardware piece that needed to be integrated.
Mac has an application called Automator that has a graphical interface providing the ability to string together known actions into a workflow. I ended up using a “Folder Action” which listens to new files being added to a folder and feeding that to a print action. Now we just needed to get the files from the form submission folder on the server to this folder on the Mac. To accomplish this quickly, I wrote a quick Python script that just polls with a “scp” command against the server and drops any new files into the folder being watched by the Automator.
The part that really sunk my time was the actual printed result that showed up on the paper. The Automator just opens the file in the associated format and issues a print command from that application. Initially, I was just writing .txt files and this forced the TextEdit app to open and print which had no notion of font size. The result was unreadable. My workaround was to write HTML files with CSS to style the text then associate the .html extension with TextEdit, thus styling the text before printing. This produced the desired results.