Harry Potter and the CLI Project

Riley Redfern
3 min readNov 15, 2020

--

Cunning, magic, and a minor crisis.

This week I was tasked with creating a CLI for my first project as a Flatiron School student. If anyone reading this knows me, you won’t be surprised by the direction I decided to go with it. The truth is that it doesn’t matter which type of API I used, this was super challenging, but a great way to wrap up everything I’ve learned so far.

I decided to pull data from the Harry Potter API which is a very clean and functional API source. It seemed to be well maintained and the data provided was not only in array format but was information I already knew, so I’d know if my app wasn’t accessing it properly.

I started by creating my different files and classes, as one of the requirements for the project is that the CLI exists not just in one file but in an ‘environment’ of files. It made the most sense for me to start at the source, so I got my API linked in as a first step. From there, I built out the backbone of a basic CLI file and a ‘Spell’ file. My goal ultimately was to have the API fetch data, Spell file sort data, and CLI file present the data to the user. Makes sense enough, right?

A problem I encountered, which is a problem I think most new coders likely experience is that I ended up with almost 100% functionality existing inside one method inside one class. I thought, “okay steps A, B and C are done now do DEFGHIJ right here just because I want to prove my program works”. Sure it was exciting to have the computer talk to me and present me with the data I wanted, but my code was messy and stressed me out just by looking at it. Also, this was risky because my program won’t be able to grow or change very well from that point and it had almost no separation of concerns whatsoever.

I got some feedback and guidance and decided to move more of the ‘sort’ functionality into my ‘Spell’ class. I did this by relocating some class methods, re-associating variables to them, and then calling them more cleanly in my CLI file. Ultimately, much nicer.

Another pretty major issue I encountered was that my API went down pretty much as soon as I’d achieved functionality! Crisis! Very luckily, I had the data in an open browser window and was able to copy-paste most of it and re-locate it to a different URL. In this way, I was able to preserve the original purpose of the app without needing to basically start from scratch. Unfortunately, I was only able to save about half of the spells so my program can’t allow the user to fully appreciate the scope of the Harry Potter universe but… all things considered I’m still quite pleased with myself.

Please watch the attached video walkthrough below as I’m really jazzed to show you guys how my program works. Again, this was such a great opportunity to really see what I’ve been able to learn in just a few short weeks.

https://www.youtube.com/watch?v=q25kkk9DqY0&feature=youtu.be

--

--