Skip to content

Commit

Permalink
Reto mouredev#18 - Ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
test0n3 committed May 2, 2023
1 parent 748a115 commit 1fa6f02
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Retos/Reto #18 - WEB SCRAPING [Difícil]/ruby/test0n3.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
# Ruby app, requires to have installed the following gems:
# - URI
# - net/http
# - nokogiri

# frozen_string_literal: true

require 'uri'
require 'net/http'
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)/)
Expand All @@ -32,4 +39,4 @@ def clean_html_snip(html_snip)
end
end

puts GetSchedule.new.pick_data
puts ScheduleHolaMundoDay.new.pick_data

0 comments on commit 1fa6f02

Please sign in to comment.