Building a Backend

In order to sort a card, you first need to understand what a card is. We have the card’s name, but how do we go from a name to parameters that you can sort? By building a database of cards that we search from, we can store information, such as the card’s colour, value, and set name, which can be used to sort the card. This database can also store users’ collection of cards, sort commands, and other pieces of info.


MySQL was an easy choice for the database format, as it allows us to select cards by numerous parameters (such as all red and white cards) or all cards worth over some threshold. Amazon RDS was also an easy choice to host this database, as the free tier was more than sufficient to hold all the needed data. A cloud-based solution was also valuable because it was trivial to update the pricing data or perform database migrations. It would also allow users to have a record of their collection without needing to have access to the Pi.

But where do we get that data? As it turns out, there are a few options. The first one we found was Scryfall, which had bulk data on all cards available for free via their API. Their bulk data had colour, set, and the names for each card, which would have been all we needed if we were just looking to sort by colour. However, we also needed to sort by value. Hence, Scryfall’s bulk data would not be sufficient.

Enter TCG Player and their API. Unlike Scryfall, it did not contain info such as card colour or set name, but it did contain the pricing data for each edition of every card. Between the two data sources, a simple Python script was written that parsed Scryfall’s bulk data to get the card properties, and then called TCG Player to get the card pricing, before inserting all that info into our database.

However, we now need an easy way to access that data. We could have our Raspberry Pi just open a MySQL connection and query the database directly, but that is a bit inelegant. We can make our lives easier and simplify the work that has to be done on the Pi’s side. So, let’s make an API of our own.

Flask is a popular framework for developing web apps in Python thanks to it’s low setup cost and ease of use. A Flask server was written, which had several routes allowing the Raspberry Pi to easily access the data without any of the cruft of writing and parsing SQL queries. It was then hosted on Amazon EC2, where we can access it at any time.

An example route and response is shown to the left, where the /cardInfo route is being used to get the details and pricing for the card ‘Arcbound Ravager’. As can be see, the info for the card is formatted in an easy to parse layout for the Pi. It is also possible to post info to the database through the API via a similar method.

This database and API forms the backbone of the software side of the project, allowing us to easily send and get relevant and up to date card info on any card we may want.

Prev | Next

All Posts