Ordering Green Coffee with Go and jq

I roast my own coffee and order the green beans from sweetmarias. I automated a big chunck of that. Here’s how.

When sweetmarias stops selling a coffee they tend to stop hosting any content about that coffee. I don’t think that this is intentional, but in any case it means any stats or recorded info they have tends to disappear pretty soon after you order the coffee. I resolved this for my personal needs by building a tool (called sm-list, written in Go) that will extract all the current coffees and their relevant information as JSON. Currently, I use it like this:

sm-list > all.json

When I order coffee, I basically want to look at the entire sweetmarias catalog. I tend to sort by score, since my favorite coffee of all time had an exceptionally high score (93!) On top of that I’m not interested in already roasted coffee, decaf, or samples. Here’s how I build up a list of coffees to review, based on the export corpus.

cat all.json |
   jq -C -s '. | sort_by(.Score) | reverse | .[] | select(.Title | test("(?i)decaf|roasted|sample") | not )' |
   less -S

I looked over the data above (annoyingly not word wrapped, yet, but one step at a time.) Based on that I chose a few coffees and made my order by clicking the URLs for each one. After ordering I stored the information about the coffees I ordered:

cat ~/all.json |
   grep -P '(Ethiopia Dry Process Kayon Mountain Taaroo|Ethiopia Dry Process Guji Shakiso Hambela|Sweet Maria.s New Classic Espresso|Ethiopia Agaro Duromina Coop|Brazil Dry Process Fazenda Campos Altos|El Salvador Honey Process Finca El Naranjo|https://www.sweetmarias.com/el-salvador-la-esperanza-h1-cultivar-6141.html)' > order.js

I commited that information to my coffee log, with the intention to use that information when I roast coffee, going forward. On top of that, I figured I’d share what I ordered with some friends:

cat order.json |
   jq -r '" * [" + .Title + "](" + .URL + "): " + .Overview + "\n"' |
   fmt -t |
   perl -pe 's/^(\S)/   $1/'

Here’s the output, rendered from the markdown:



If you’re interested in roasting your own coffee I wrote up how I do it. That description is a little out of date, but it gives you enough detail to get started yourself.

(The following includes affiliate links.)

Also, sm-list is written in Go; if you want to learn more about programming Go, you should check out The Go Programming Language. It is one of the best programming books I’ve read. You will not only learn Go, but also get some solid introductions on how to write code that is safely concurrent. Highly recommend. This book is so good that I might write a blog post solely about learning Go with this book.

I haven’t started reading it yet, but on my list in programming books to read is Designing Data-Intensive Applications. I have heard great things.

Posted Wed, Sep 4, 2019

If you're interested in being notified when new posts are published, you can subscribe here; you'll get an email once a week at the most.