How Hanson Inspired My CLI Data Gem Project

Posted by Allyson Hotchkin on August 15, 2018

As I approached my first project for Flatiron School, I had no idea what I wanted to do. The task: build an application that provides a Command Line Interface (CLI) to an external data source. It sounds simple enough (does it, though?), but the possibilities were seemingly endless. The common suggestion was to pick something I’m interested in. Well, anyone who knows me could tell you that I love Harry Potter. Maybe that could have been something if I hadn’t just thought of it as I type this. That’s okay though, I also happen to love music. I know, I know, I can’t create a Music CLI app as that is too similar to the other OO Ruby final project. But what about a Concerts CLI app? That could work…

Okay, so what concerts pique my interest? Well, I did go see Hanson twice in the past year. Before you ask — yes, the three brothers who gifted the world with MMMBop back in the ‘90s are still making music. And luckily for us, they’re going to be at the NY State Fair this month (August 30 at 8pm for anyone who’s interested)! I was onto something. I did a little research and came upon the Chevy Court Concerts website, which lists out all concerts taking place at Chevy Court during the state fair. So it was decided — I’d build a CLI app that would list out all Chevy Court concerts and their details. I had an idea that I was excited about, I just had to figure out what to do next.

First things first, I wanted to make sure the website was scrapable. After a few hours of experimenting, I figured out how to get the information I wanted — the band performing, the date and time of the performance, and the URL for that concert. That was all well and good, but it was becoming more and more evident that at some point I was actually going to have to start writing the program, and I truly had no idea where to begin. Avi was kind enough to provide a video walkthrough where he started a similar project. So why not follow along step-by-step? This proved to be very useful. With Avi’s help, I had the shell for my very first program. Thanks, Avi!

Next, I needed to figure out how to set up my classes. Much of this project depends on scraping. Did I want to include my scraper methods within my Concert class, or did I want to keep them separate? It didn’t seem to matter much either way, but I liked the idea of setting up a Scraper class. It was challenging at first to get the Scraper class to work with the Concert class, and I reconsidered my structure. However, with a little persistence (and a smidge of help) I was able to get the classes to work together while keeping them separate. And in the end, I was really glad I did (you’ll see why soon).

At this point I had a program that functioned pretty much as I wanted it to. I had a Scraper class to scrape data from a website, I had a Concert class to create instances of concerts, and I had a CLI class to allow for user interaction. Through the CLI, users could see a list of concerts and then select a concert for details (date, time, and URL). This was great and everything, but I wanted to find a way to give the user a little more information. I noticed that each URL led to a concert-specific webpage with a short biography of the band in question. What if I could find a way to scrape some of the band information for the user? As it turns out, all of the band bios were contained in <p> tags. Well, all except for Smokey Robinson’s, that is (dang you, Smokey, with your generic <div> tags and your voice of an angel). But with a little scraping practice and some sneaky use of regular expressions, I figured out how to scrape Smokey’s biography too. This was going great! At least until a few nights ago…

via GIPHY

Clearly, whoever is in charge of the Chevy Court Concerts website didn’t get the memo that I was using it for a project, and would prefer that no changes be made prior to me submitting said project. I was putting the finishing touches on my program and testing out some of the user interaction, when I received a new error message. Out of nowhere the program couldn’t scrape the biography for half the bands. I did a little more digging, only to discover that what had once been a list of 26 concerts was now a list of 54 concerts, parades, and other events. Upon further investigation I noticed that the concerts within the first half of the list still had their band bios in tact, while the concerts in the second half of the list no longer had any bios. This particular issue seemed like it might be a mistake. Spoiler alert: it was indeed a mistake and was fixed within 24 hours.

So without having to put in much work at all, the majority of the program was working again. However, I still found myself in a bit of a predicament. While all of the bands had bios, none of the parades or other events had additional information. So if a user selected to see the details on one of those events, they would receive an error message. I had a couple of options. I could figure out a way to exclude any events from the list that weren’t part of the original 26 concerts. Or I could figure out a way to incorporate these events in a different way. I decided to accept the challenge and see how I could use this additional information in my CLI app. I started with the parades. These seemed to function pretty similar to the concerts, with the exception of the bios. So why not create a Parade class? It turns out this was pretty easy to manage since I had my scraping logic separate from my Concert class already (woohoo!).

I was then left with these oddball events that repeated themselves over and over throughout the duration of the fair. I know what you’re thinking. “Allyson, why didn’t you create an Other class and give the user the opportunity to select one of those events and see all of the dates and times that it’s taking place?” Funny you should ask, because that’s exactly what I did! It took some tinkering since the Other class had to function differently from Concerts and Parades, but with a little trial and error I managed to get it to work.

Overall, this has been a very educational experience. I still can’t believe that I essentially built something from scratch that actually functions (although I’m sure could use some refactoring). Sure, it wasn’t exactly what I set out to do. But as frustrated as I was when the website changed, in the end I was grateful for it. For one, I’m sure this is the first of many (MANY) times where I’ll need to adapt my code because of something beyond my control. But it turned into a great opportunity to figure out how to incorporate this new information. I’m pretty pleased with the way everything turned out. I think as a reward to myself I might just have to go to the state fair this year. Maybe on August 30 to see Hanson?

via GIPHY