-
Notifications
You must be signed in to change notification settings - Fork 2
/
hack.rb
104 lines (90 loc) · 3.15 KB
/
hack.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
require 'nokogiri'
require 'mechanize'
require 'open-uri'
# --------------------- VARIABLES -------------------------------------------------
movies = []
theaters = []
# --------------------- CLASS -----------------------------------------------------
class Movie
attr_accessor :name, :value, :theaters
def initialize(args)
@name = args[:name]
@value = args[:value]
@theaters = []
end
end
class Theater
attr_accessor :name, :value, :horario, :price, :address
def initialize(args)
@name = args[:name]
@value = args[:value]
@horario = args[:horario]
@address = args[:address]
@price = args[:price]
end
end
# --------------------- GET Movies and Theaters from peru.com --------------------
doc = Nokogiri::HTML(open('http://www.peru.com/entretenimiento/cine'))
p "loading movies and Theaters..."
doc.css('li.list-item').each do |li|
name = li.children.text
value = li.attributes["data"].value.to_i
if value > 500
movie = Movie.new name: name, value: value
movies.push movie
else
theater = Theater.new name: name, value: value
theaters.push theater
end
end
p "Done"
# --------------------- Get Poster_PAth --------------------------
# listado = doc.css('div.listado_peliculas').children.children
# poster = listado[1].children[1].children[1].children[1]
# poster_movie = poster.attributes["alt"].value
# poster_path = poster.attributes["src"].value
# p poster_movie
# p poster_path
div_listados = doc.css("div.listado_peliculas")
div_listados.each do |div_listado|
ul_div = div_listado.children[1]
ul_div.children.each do |li|
if li.class == Nokogiri::XML::Element
figure_div = li.children[1]
a_div = figure_div.children[1]
img_div = a_div.children[1]
img_attributes = img_div.attributes
poster_movie = img_attributes["alt"].value
poster_path = img_attributes["data-original"].value
p poster_path
end
end
end
# --------------------- Get Horarios from peru.com form --------------------------
# agent = Mechanize.new
# page = agent.get 'http://www.peru.com/entretenimiento/cine'
# movies = [movies.first]
# theaters = [theaters.first]
# p "loading Schedules for movies"
# # File.open("schedules.txt", "a+") do |file|
# movies.each do |movie|
# # file.puts "========="
# # file.puts movie.name
# theaters.each do |theater|
# form = page.forms[1]
# form["pelicula"] = movie.value
# form["cine"] = theater.value
# response = agent.submit(form)
# noko = Nokogiri::HTML(response.body)
# address = noko.css('td.direccion').children.text
# price = noko.css('td.precio').children.text
# schedules = noko.css('td.horario').children.text
# overview = noko.css('p')[2].children.text
# p overview
# movie.theaters.push Theater.new name: theater.name, value: theater.value,
# horario: schedules, price: price, address: address
# # file.puts "- #{theater.name} - #{price} - #{schedules}"
# p "#{movie.name} - #{theater.name}"
# end
# end
# # end