From 1fa6f02edf300c6c98d0a08eac8ebb7dfaa38977 Mon Sep 17 00:00:00 2001 From: Carlos A Date: Tue, 2 May 2023 17:06:48 -0500 Subject: [PATCH] Reto #18 - Ruby --- .../ruby/test0n3.rb" | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git "a/Retos/Reto #18 - WEB SCRAPING [Dif\303\255cil]/ruby/test0n3.rb" "b/Retos/Reto #18 - WEB SCRAPING [Dif\303\255cil]/ruby/test0n3.rb" index 77453e03f2..aa13a0dd0f 100644 --- "a/Retos/Reto #18 - WEB SCRAPING [Dif\303\255cil]/ruby/test0n3.rb" +++ "b/Retos/Reto #18 - WEB SCRAPING [Dif\303\255cil]/ruby/test0n3.rb" @@ -1,3 +1,8 @@ +# Ruby app, requires to have installed the following gems: +# - URI +# - net/http +# - nokogiri + # frozen_string_literal: true require 'uri' @@ -5,22 +10,24 @@ require 'nokogiri' # class GetSchedule, get on date schedule -class GetSchedule +class ScheduleHolaMundoDay HOLAMUNDO_URL = 'https://holamundo.day/' def pick_data uri = URI(HOLAMUNDO_URL) res = Net::HTTP.get_response(uri) - print_schedule(res.body) if res.is_a?(Net::HTTPSuccess) + show_schedule(res.body) if res.is_a?(Net::HTTPSuccess) end - def print_schedule(response) + def show_schedule(response) doc = Nokogiri::HTML(response) - schedule = find_schedules(doc)[0] + schedules = find_schedules(doc)[0] - clean_html_snip(schedule).drop(8).map(&:content) + clean_html_snip(schedules).drop(8).map(&:content) end + private + def find_schedules(html_body) html_body.css('article.notion-page-content-inner').select do |article| article.content.downcase.match?(/(agenda 8 de mayo)/) @@ -32,4 +39,4 @@ def clean_html_snip(html_snip) end end -puts GetSchedule.new.pick_data +puts ScheduleHolaMundoDay.new.pick_data