Building a library system with QR codes

3 minute read

A year ago, I began to learn the game of go. I've since joined the San Francisco Go Club. Since COVID-19 has begun to dull in the Bay Area, the club has undergone a renaissance. Some very dedicated members helped find a new physical location for the club, a beautiful space in the Japan Center mall. The dojo is outfitted with many tables, go boards, go stones, and a library of books.

A few weeks ago, one of our members asked how we could check out books in the library. It occurred to me and my friend Josh Hull that we could build an application to check out books. This technically-oriented article is a story of how we built it.

Every ORM documentation uses the examples of libraries, books, authors, etc. It was a little surreal pulling actual code straight out of examples of ORM libraries. I love ruby on rails, especially for small apps like this with a limited scope, and modest technical complexity. With a few `rails generate model etc` commands, we were off to the races.
Building an app to let people check out books seems simple at a first glance, and you wouldn't be wrong. Just slap a QR code on a book, have patrons scan it, sign in, check out, done! The interesting part laid in how the app connected to the physical world of books on a library shelf.

Generating a QR code sticker and putting it on a book is tricky. What kind of sticker would we use? How would we print it? What format should we use? Initially, we considered using a thermal printer, which can print out a small QR code perfectly sized for a book. But the file format was proprietary, and there was no way to edit it programmatically. This would have meant dealing with a lengthy manual process for generating each individual tag.

Using printable label sheets, such as this one seemed like a better option. If we could find a way to programmatically generate their content, then we could rid ourselves of the burden of individually printing each sticker for hundreds of books.
The question was how to generate a printable page of labels in the exact format dictated by our label sheet of choice? Perhaps this could be done using a web page, styled to fit our purpose? In the end, the pylabels library is what came to the rescue. It provides an interface to generate a pdf file, with convenient options to set the number of columns, rows, and various types of spacing. With this, it was merely a matter of converting the dimensions specified on the label sheet to pylabel parameters. With a bit of tweaking, we had a printable document which matched the label sheet perfectly. In case this is of any help to anyone else having the same issue, I've created a GitHub gist documenting the skeleton of the approach.

So what about the contents of the label? We needed to include a few things:

  • A QR code which would lead to the book's permalink
  • Title
  • Subtitle
  • Author
  • SF Go Club watermark

There's no way around this: we needed to digitize the books in the library into a database, in order to generate a file which could then be used as an input to our label printing utility. So that's what a group of friends and I did together for a couple of hours one afternoon. We rediscovered the fun of dividing labor and setting up a production chain. One group would enter text information about the book in a web form, while the other group edited the book to snap a picture via their phones.

With a digital representation of the library, we could finally generate a file representing the library's contents, and print the labels. A couple of hours later, the labels were all stuck on the books, and the system was ready for use.

The SF Go Club's library is available at https://library.sfgoclub.com. Members can use it to scan a QR code and borrow up to three books. But most of all, my friend and I had a fun time building it together.