Class: Scrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/scrapper.rb

Constant Summary collapse

URL =
"https://next-episode.net"

Class Method Summary collapse

Class Method Details

.list_scrapperObject



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/scrapper.rb', line 4

def self.list_scrapper
  url = Nokogiri::HTML(open(URL + "/recent/"))
  url.css("#recents_wrapper td").first.css("h3").each do |episode|
    show = Show.find_or_create_by_name(episode.text)
    # show.save
    if show.url == nil
      show.url = episode.children.attribute("href").value
      self.show_scrapper(show)
    end
  end
end

.show_scrapper(show) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/scrapper.rb', line 16

def self.show_scrapper(show)
  url = Nokogiri::HTML(open(URL + show.url))

  show.summary = url.css("#summary").text
  url.xpath("//*[@itemprop='genre']").each{|genre| show.genre << genre.text}
  show.channel = url.css("#middle_section .sub_main")[1].text.split(" at ")[0]
  show.showtime = url.css("#middle_section .sub_main")[1].text.split(" at ")[1]

  url.xpath("//*[@class='subheadline']").remove

  show.status = url.css("#middle_section").text.gsub("\t","").split("\n").reject(&:empty?)[4]
  show.date = url.xpath("//*[@id='next_episode']").text.gsub("\t","").split("\n").reject(&:empty?)[3]

  if show.status == "Running" && show.date == Time.now.strftime("%a %b %d, %Y")
    show.season = url.xpath("//*[@id='next_episode']").text.gsub("\t","").split("\n").reject(&:empty?)[4]
    show.episode_name = url.css("#next_episode .sub_main")[0].text
    show.episode = url.css("#next_episode .sub_main")[1].text
    show.save
  end
end