Skip to content

Commit

Permalink
date error scraper.rb
Browse files Browse the repository at this point in the history
Add a guard clause: Before the Date creation, add a guard clause to skip any invalid date values.
  • Loading branch information
jamasalbertastash committed Aug 9, 2023
1 parent d5864f8 commit 385149e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions scraper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@ def scrape_page(page, comment_url)

table.search("tr")[1..-1].each do |tr|
day, month, year = tr.search("td")[3].inner_text.gsub(/[[:space:]]/, ' ').split(" ")

# Print the date values for debugging
puts "Parsed Date: Day: #{day}, Month: #{month}, Year: #{year}"

month_i = Date::MONTHNAMES.index(month)

# Guard clause
unless day && month_i && year
puts "Invalid date values. Skipping..."
next
end

record = {
"info_url" => tr.search("td a")[0].attributes['href'].to_s,
"comment_url" => comment_url,
Expand Down

0 comments on commit 385149e

Please sign in to comment.