Fuzzy searching Amazon purchases in Alfred

When I set out to get a list of all Amazon items ever purchased into an Alfred I thought it would take me half the time and have zero surprises. Twice the time later and I now know I’ve purchased over two thousand different items since 2006.

Let’s dig into the original problem. I’ll state this as a goal: get Amazon items purchased into Alfred’s omni search box.

I had some things I knew ahead of time:

  1. Amazon offers a way to download a list of orders and such for your account as a comma-separated values (CSV) file.
  2. Alfred has a standard Script Filter JSON format for filtering a dataset by fuzzy text matching.

Achieving this goal is not uncommon—I’ve written Alfred filters before—and often the hard part is getting the data in the first place, not generating the JSON blob to feed into Alfred. Here I encountered the reverse. Getting the data was easy but processing it wasn’t as straight forward.

I expected to take the CSV from Amazon and feed it into jq. I’ve done this before and it mostly works fine. The benefit of using jq is having to think about and manage less complexity. Reaching back to Python—which is what I ended up doing—has additional temptation towards complexity.

Python isn’t bad. I would probably be more efficient overall if I started with Python first. The problems come up when I need to tweak or change something. Extending a jq script is often trivial because you are only allowed to do trivial things by design.

You can find the full Python snippet in this Gist.

written September 6th, 2022

September 2022

Can’t find what you’re looking for? Try hitting the home page or viewing all archives.