CLI Data Gem Project
hi there
So, this is the blog post for the first project for Flatiron, the CLI Data Gem Portfolio Project.
The requirements of this project are as follows. The project must provide a CLI, it must provide access to data from a web page, the data provided must go at least one level deep (a “level” is where a user can make a choice and then get detailed information about their choice) and it must make use of good OO design patterns.
My project scrapes data from the Lexington Chamber & Visitors Center’s website, specifically, their Visit Lexington’s Community Events tab
( http://www.lexingtonsc.org/community-events).
The program starts off with an intro:
“Welcome to the Lexington Community Events page.
Please wait while the events are loading…”
The events are then displayed from 1 to a dynamic number (#{Events.all.length}.”) because the events on the website change according to the date, the list is dynamic. A couple of days/weeks from now, the length of the list will probably change, because some events would have already happened and have been taken off the website and/or the Lexington Chamber & Visitors Center might have added new events to their calendar.
After the events are listed, another message pops up and it prompts the user to select an event, again, between 1 and a dynamic number.
Here’s what it looks like in VS Code:
“Please select an event between 1 and #{Events.all.length}.”
That “#{Events.all.length}.” will be seen as an actual number, not as (#{Events.all.length}).
When I use the app, I select 2, which for right now is the Chicken Bog Lunch Meal @ Jamil Shrine Center (Drive Thru & Delivery) | 11am. But I’m sure it will gone in a few days time.
So, when the number 2 is typed and enter is pressed the app will respond with
“You have selected: #{index}. #{chosen_event.name}”
“The date(s) for the event is/are:”
The #{index} & #{chosen_event.name} corresponds with the websites listed events and shows the selected event. And on top of that, going one level deep, it also shows the date(s) for the event. Because I chose 2, it will respond like so:
You have selected: 2 . the Chicken Bog Lunch Meal @ Jamil Shrine Center (Drive Thru & Delivery) | 11am
The date(s) for the event is/are:
September 11, 2020
The reason for the “date(s)” is because some events, like the one above, event number 2, is only one day, whereas other events can be several days, weeks or months long, like event number 7.
You have selected: 7. Fall Moonlight Movie Nights Drive-Ins 2020 | 7:30pm
The date(s) for the event is/are:
September 18 — November 13, 2020
In a snapshot, that’s what my app does.
This app solves the issue of not knowing what the date of the event is when the event title is displayed, and I think that’s what great about it…why, a couple of weeks ago, I had no idea how to do this…at all, and now I can do it, and I think that is just quite amazing.
A couple of things I was struggling with was 1) getting the correct elements from the website, and 2) making sure I didn’t hard code the numbered events because they would be changing according to time.
I was able to get some help from some cohortians and some people from online forums to help me resolve these issues.
As far as choosing the correct divs from the website, we just had to do some trial and error to get it right. We tried
position: absolute; left: 0px; top: 0px; transition-property: opacity, transform; transition-duration: 0.4s; transition-delay: 0ms; transform: translate3d(0px, 20px, 0px);
month-cont all September
month-list normal-month-list
but they were too broad, we need only one row so it could be iterated.
After some tries, we finally got the line that was needed:
events-list all row
that line provided the row that could be iterated.
The following lines provided the names and dates of the events
col-xs-7 col-md-7
col-xs-2 col-md-2 date-list
With the second issue, I wanted to make sure that the numbered event were dynamic and not static because, as stated before, the list of event would change as time went on and I wanted to make sure it was future proof. The best solution was the .length, which returns the number of elements in an array, in this case, it was the Events.all (or self.all) array.
def self.all
@@all
end
def initialize(name, date, index)
@name = name
@index = index
@date = date
@@all << self
end
Even though it’s a simple app because for now, I wanted to do something easy and simple and I’m ok with that. When there’s time, I look forward to refactoring it and making it more complex in the coming weeks and months.
Until then, i’m gonna try and checkout the Chicken Bog Lunch Meal @ Jamil Shrine Center (Drive Thru & Delivery) | 11am on September 11, 2020.