Programming My First Ruby App

Writer’s Note: This was a live blog of my experience writing my first piece of software completely independently. If it looks like I trailed off in the middle of a thought… I probably did. I’ve tried to sew it all together to make it seamless but this project took place over the course of a month.

Ruby app thing available here: https://github.com/srolandmarshall/phish-cli-app

Enjoy!

********

It’s that time. My first assessment and first Ruby gem.

I’ve learned along the way that to tie a new area of programming to something that you understand is a great way to teach yourself. If it’s something you also enjoy, it will intrinsically link itself to that happiness.

I’m a Phish fan. I’ve been to 20+ shows, plan on seeing three more the weekend of July 28th.

Phish is a unique band not only in their sound, but in the amount of information available about them on the internet. Every show, setlist, lyric, song, musical interlude is contained within a fan-built and maintained database at Phish.net. So I thought, what better a project to show off my OO Ruby and scraping skills than a website with every Phish show?

Shows belong to Tours, Setlists belong to Shows, Songs belong to Setlists, each Song has its own statistics — it was a match made in Object-Oriented heaven!

My plan was to go through them linearly, then just allow the user to access them like a dictionary. Then I realized Phish has over 1600 shows. That’s a lot of scraping. And a lot of time. My computer, no slouch, averaged about a show every 2 seconds. Estimating 1600 shows * 2 sec per show = 3200 sec / 60 sec per min = ~53 min of scraping.

Even once I finally got through all of these, Phish was currently playing a show, and that show didn’t have a rating yet, causing this after 50+ mins of waiting:

So I modified mid-stream to allow the user to type in the info they were looking for and then scrape it on demand, instead of holding them all on RAM.

So from there I made a tour scraper, and decide to get to CLI just to get two things done at once.

I made a really crude CLI that asks for an input:

Then I quickly developed a way to search the tours by year:

Then I worked on getting a show to display on its own, but ran into a bigger hiccup! One of my earlier scrapers was funking up the joint:

At first I thought it was the setlist scraper, so I rewrote it to success…

But then realize certain shows would still cause it to crash. Which made me rewrite the ORIGINAL song scraper, which was based on counting cells and not good use of Nokogiri. It was causing dates to go into the name cells and vice versa.

Once everything was back to how it should work, I finished up the tour selector and worked on wrapping it into a greater “show selector” menu option. You can then pick show by date or by tour. I found this good feature called Date.parse within ruby which takes standard inputs for dates and turns them into the YYYY-MM-DD format, which is handy because phish.net has a URL shortcut where you just enter http://phish.net/setlists/d?#{date} with date in the proper format to get all the shows on that date. If there is only one show, it will bring it to that show. Sometimes days have multiple shows, unfortunately, so a special exclusion has to be developed for that…

Realizing this was going to be the heaviest goal left, I figured it’s better to get it over with ahead of time. In tackling the show finder, I ended up finding an even better URL shortcut that always shows options of shows on that day, and will not auto load a page. This required some case switching, however, and a bunch of Nokogiri noodling to do it.

Side note: Nokogiri noodling is a term I created where you frantically enter random stuff into pry on terminal trying to get the data of information from Nokogiri that you want displayed. I figured out how to get an attribute tag from an image or how to loop through all the links in a cell to get text and links. Once I figure it out in terminal I just copy, paste, and modify in Atom. and move on to the next problem. It’s a pretty agile workflow, but I should be commiting to git each time I do this. In due time.

I quickly tackled being able to search a song by name, using some of the above methods I had mentioned. I then tidied up the CLI menu by creating a repeater method that basically took users back to the main menu. I’m using recursion a lot which surprisingly wasn’t covered in the Ruby track of the class I was taking, but I remember it from my Java days.

A few tests to work out some bugs and I think the alpha version is ready. It can look up a show, it can look up a tour, it can look up a song. Those are the basic objects of “Phish-dom”. If I want to keep going there’s plenty to dig into.


Posted

in

by

Tags: