I love it when things I like come together. Today, it’s my hobby of utilitarian hobby coding combining with my enthusiastic and occasionally proficient video gaming. I’ve played Destiny for a couple of years as my primary gaming diversion, and now play Destiny 2 pretty regularly.1 I try to be conscientious about playing intentionally and keeping track of my play.

In the course of play, Destiny and Destiny 2 drop a lot of loot, some of which is important, rare, or particularly fun. I want to associate special memories with some of them, like the armor piece that dropped after a spectacularly fun PvP match, or the weapon rewarded for completing a quest just in the nick of time with a clutch move by a team member.

I will sometimes make a notes in my Day One or paper journal about having a notably good time in a game, but my hobby coder side always wondered if there was a way to make something more systematic. Bungie provides a pretty sophisticated API that has enabled an ecosystem of stats trackers and item managers (the latter of which are extremely useful, even necessary; my favorite is Ishtar Commander). Surely I could build myself a sort of play journal using the API! I told myself, several times over the past year, but I didn’t get around to actually doing it until I had some spans of free time over my winter holiday.

As usual for me and these kinds of things, just getting OAuth to work properly was a pain in the ass. After that it was a matter of tinkering over a handful of days to piece together a useful understanding of the API endpoints that I needed to use. Unfortunately for my intended use, the information returned with game inventory doesn’t include a datestamp, so it’s not straightforward to make a dated list of all my characters’ awesome equipment in a single go.

So I built a short script and several fish shell commands that 1) update my OAuth token, 2) fetch my current complete inventory, 3) compares it to the previous inventory, 4) pulls out the new items, 5) filters out the common items and leaves just so-called Legendary or Exotic gear, 6) and deposits that smaller, filtered list in a json-formatted document.2 I can run this series of operations whenever I want to update my “journal” and then annotate the records I care about with notes, about who I played with, what activities we ran, and anything else I want to remember.

Here’s an example from one of these “diary” files:

{"item":"Tarantula","type":"Legendary Linear Fusion Rifle","hash":2502422775, "notes": "Maximum power linear fusion. I haven't played much with these so will give this one a try (have a few other copies). I'm not sure what this can be infused into, anyway."}
{"item":"Out of Options","type":"Legendary Submachine Gun","hash":2700862858}
{"item":"Main Ingredient","type":"Legendary Fusion Rifle","hash":3445437901, "notes":"Masterworks max power Main Ingredient from a clan engram. This one is a keeper, though I may re-roll it from reload speed."}
{"item":"Skyburner's Oath","type":"Exotic Scout Rifle","hash":4255268456, "notes":"Xur is in town! I didn't have this one - from the exotic engram. I think I have the ornament sitting in the vault from like week 1."}
{"item":"It Stared Back","type":"Legendary Sword","hash":1018072983, "notes":"Masterworks It Stared Back! Ran the raid from a Calus CP today with several of the clan, had a great time, and we got it done."}
{"item":"Emperor Calus Token","type":"Legendary Redeemable","hash":1505278293}

Along the way, I found my favorite, favorite new tool: jq. I’m relying on it extensively throughout this little system, basically to do all the lifting with the json returned from the API, both for managing the Oauth info and for dealing with inventory data. It’s a wonderful tool.

jq parses json wonderfully, and can format output for new uses, so:

for i in (ls diary*.txt)
  echo "## I played Destiny:" $i \n | sed s/diary-// | sed s/\.txt// ; cat $i | jq -r '. as {item: $item, type: $type, notes: $notes} | if ($notes | length) > 0 then " * **" + $item + "*** / " + $type + "\n    * " + $notes + "" else " * " +  $item + " / " + $type end '

… produces this snippet of formatted output, excluding the items where I haven’t made any notes:

I played Destiny: 2018-02-15

  • Shepherd’s Watch / Legendary Sniper Rifle
    • Today was a good day to play Crimson Doubles! Really, really fun games tonight, mostly winning big: I went 4, 15 and 6 KDA. Warlock rifts everywhere, Uriels and Better Devils, lots of grenades and some pretty cool nova bombs. This was fun.
  • Cadenza-43 / Legendary Pulse Rifle
    • The TWAB today says pulse rifles are coming back to the meta… so we’ll see! I have some of just about everything ready to try our further. (Your time will come, Autumn Wind.) I also need pretty badly to do some vault cleanout: currently at 190200 slots and have a bunch of duplicates and others to take care of. Will have to spend some time with DIM this weekend.
  • Perseverance / Legendary Auto Rifle
    • A couple of these have dropped but I haven’t tried them. I like the name.

This is really fun! I run my string of commands every time I want to make an update, then I can annotate the output in my current editor of choice.3 At some point I’ll push that output into some nicely-styled calendar, much more like a real play diary, perhaps with an integration to actual play time during the period depicted in my log. (That data is also available via the API; picture a heatmap by day or week along with the entries, maybe images of items from the manifest, too.) I have half a mind to try to make it a small web app usable by more than just me.

A fun side effect of building this is figuring out how to move items around in my inventory along the way. Nothing makes me feel more like a hacker than typing something into a shell and watching my Hunter equip a sweet rocket launcher in a video game. Ultimately, in my quest to be thoughtful about my game time, I learned a bunch about working with json and oauth and made something that multiplies my enjoyment of both the gaming and journaling that I do. I’m calling that a win.

  1. My list of non-Destiny games to play is getting longer, though! [return]
  2. I’m so pleased that almost the entire workflow is just a series of shell commands. The script only manages OAuth and performing one of the actal API calls, and all the other work is done at the shell. It’s a neat example of the power of flexible, loosely-joined *nix-based tools. [return]
  3. Currently I’m heavily into vim at home, though at work I’ve recently picked up emacs and org-mode (again) via spacemacs. [return]