#Refactoring Command-Line Interface Project
Pamela Torres-Rocca
Posted on June 17, 2021
Recently I needed to refactor an application that I had written for the first project in my coding bootcamp. This was a scraper that collected data from an urgent care website to give the user the first available appointment time at their desired location.
The CLI no longer scraped the appropriate data due to some changes to the site. To correct this, many of the changes only required modifications to the data returned to get it to display properly. The office phone number was displaying information in addition to the phone number that was not relevant. This just required adding on the gsub method to remove the data that I did not want to display.
office.phone_number = office_details.css('a[href]').text.gsub("Get DirectionsBook Urgent Care AppointmentBook COVID-19 TestBook Telemed Appointment", " ")
What made scraping easier on the new site was that the urgent care center information was now displayed in one column instead of two. I no longer needed to create two arrays and zip them together which had been very time consuming.
The site is designed to list the current available appointment times on the same page that lists each individual urgent care center. The site currently lists the next available time as "Invalid client specified". Previously I had been scraping the information off a second url which now did not work. Now the desired information was actually contained on each sites individual page in a dropdown menu contained in a iframe.
To get this information I wrote code to scrape the url for each individual urgent care centers site off the main page and stored it in a variable called url. I then passed this variable into a new method called get_waittime. The scraper then does to this new url and uses the waitir gem to wait until the element that identifies the iframe is loaded on the site.
def get_waittime(url)
@@new_browser = @@browser
@@town_page = @@new_browser.goto(url)
js_doc = @@new_browser.div(id: 'left-area').iframe.wait_until(&:present?)
@wait_time = js_doc.button(data_id: "timeSelector").text.gsub("\n", " ")
Urgentcare::Office.all[0].next_available = @wait_time
end
The next available wait time is then stored in a variable which can be added to the office object and displayed to the user.
Posted on June 17, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.