11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/this_day_in_history/history_scraper.rb', line 11
def make_events
self.get_events.each do |e|
if ThisDayInHistory::Events.all.none?{|event| event.title == e.css(".title").text}
event = ThisDayInHistory::Events.new
event.year = e.css(".year").text
event.title = e.css(".title").text
event.category = e.css(".category").text
event.story = e.css("p").text
if event.category != "Lead Story"
event.link = e.css(".title a").attribute("href").value
new_page = Nokogiri::HTML(open("https://www.history.com#{event.link}"))
event.full_story = new_page.css(".article").first.text.strip
end
end
end
end
|