22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/new_york_films/film_finder.rb', line 22
def self.scraper
doc = Nokogiri::HTML(open("http://www.screenslate.com/"))
doc.search("ul li.screenings__venue___2EEUR li.screenings__screening___2wxaa").map do |film|
@@all_films << screening = NewYorkFilms::Screening.new
if film.parent.parent.css("h3") != nil
screening.theater = film.parent.parent.css("h3").text
else
screening.theater = "not provided"
end
if film.css("a.screening__link___1rTIP") != nil
screening.title = film.css("a.screening__link___1rTIP").text
else
screening.title = "not provided"
end
if film.search("div.screening__details___2yckE span")[0] != nil
screening.director = film.search("div.screening__details___2yckE span")[0].text
else
screening.director = "Not listed."
end
if film.search("div.screening__details___2yckE span")[1] != nil
screening.year = film.search("div.screening__details___2yckE span")[1].text
else
screening.year = "not provided"
end
if film.search("div.screening__details___2yckE span")[2] != nil
screening.length = film.search("div.screening__details___2yckE span")[2].text
else
screening.length = "not provided"
end
if film.search("div.screening__showtimespacing___17fBg span.screening__showtime___3oJD6") != nil
screening.times = film.search("div.screening__showtimespacing___17fBg span.screening__showtime___3oJD6").text.gsub("pm","pm ").gsub("am", "am ")
else
screening.times = "not provided"
end
if film.search("a.screening__link___1rTIP").attribute('href') == nil
film.attribute('href').value = "http://www.screenslate.com/"
end
screening.website = film.search("a.screening__link___1rTIP").attribute("href").value
contact = film.parent.parent.css("a").attribute("href").value
venue = Nokogiri::HTML(open("http://www.screenslate.com#{contact}"))
if venue.css("div.venue__info___2bLnH p") != nil
screening.location = venue.css("div.venue__info___2bLnH p").first.text.gsub("Location ", "") if venue.css("div.venue__info___2bLnH p").first.text.include?(", NY")
if venue.css("div.venue__info___2bLnH p")[1]
screening.location = venue.css("div.venue__info___2bLnH p")[1].text.gsub("Location ", "") if venue.css("div.venue__info___2bLnH p")[1].text.include?(", NY")
end
else
screening.location = "please see theater's website."
end
end
end
|