Pinball Map App Now Available On Tidbyt
I love a gadget. I think I get this from my father, a locally famous gadgetman who filled my K-12 bedroom with his hand-me-down computer equipment and old televisions. I find it very satisfying to take something that is (or looks) slightly away from its time, and shoehorning something new into its vocabulary. A new (but kind of old looking) thing that I have recently been very into is the TidByt. For those that aren’t familiar with it, the TidByt is a little box that you put on your desk that displays micro-messages and images in a style that my children would describe as “block old timey art like your basement Nintendo”. It looks very cool! And, you can write your own programs for it. I made an app that shows me when the next bus was going to show up in front of my house. Could I just look out the window and see? Maybe! I’m not going to risk eye contact with a passerby though. With my transit problems solved, I decided to make something that would show me the three most recent pinball machines added near by house. How did I do it, you may have wondered? Maybe you didn’t wonder before, but are starting to wonder if maybe you do wonder? I don’t know. And frankly, I don’t have control over that side of the conversation.
To make this work, the first thing that I needed to do was actually get the Pinball Map API to tell me what the three most recent machines in the area were. I cracked open the PBM code and was immediately lost. There’s a lot of filters, and I’m guessing that we have all the building blocks in place to pull all the locations near you, and then make additional API calls to figure out the most recently added machines from all those locations. But my brain is addled, and I didn’t want to lose my creative momentum by thinking too hard about difficult problems. So, I decided to write an entirely new API to handle this single use-case. Behold, /api/v1/location_machine_xrefs/most_recent_by_lat_lon.json. If you pass this thing a latitude and a longitude, it will pass you back the three most recent machines added within 50 miles of your location. It does it with speed, and without complaint. But this is bad code, everyone. This is not something I’m proud of doing. And I’ll briefly tell you why, if that’s OK:
- The naming of this API is not very descriptive. “most recent”. Most recent what? It’s not most recent location_machine_xrefs, as the naming convention may suggest.
- It defaults to machines within 50 miles of you. That’s kind of a beefy default. It’s overrideable, but it feels like a copy-paste job.
- It hardcodes a limit of the three most recent machines. Maybe you want the five most recent machines?
- Maybe the biggest sin of all, it returns string values of “LOCATION @ MACHINE NAME” and nothing else! What if you want to pull location, machine ( and date added?) and then do the formatting on your end? Tough luck.
So, I’m not super proud of the API piece. It was a rush job to get me moving on the TidByt stuff, and the end result feels a little lazy. If someone sees value in the endpoint and wants additional features/flexiblity, just email Ryan and tell him that and then he’ll tell me that. This is Scott, by the way. I would be happy to update this code on your behalf.
After the plumbing was stuffed under the floorboards, it was time to make a TidByt. They have a pretty decent overview of the whole ecosystem here, and I found it pretty easy to get things up and running. I think it’s written in GoLang, but uses some kind of Python-ish DSL or something? I never really dug into that too much. My Python is pretty basic, and I never needed a command that wasn’t available in TidByt. I found that most of my time was spent in formatting the output to fit on a pretty small display. It’s not easy to display a lot of text on this thing, so you have to get creative with what you put where. I don’t know that I landed on the best interface, but here’s what it ended up looking like:
The whole thing is open source, so feel free to take a look if that is your deal. We’d love to hear about your experiences using it. Just search for “Pinball Map” on the app library, and it should pop right up.
Thanks for looking – Scott