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
|
# File 'lib/tourist.rb', line 6
def self.tour_site(site_name, site_address, image_location, depth = nil, view_width = 1000, view_height = 1000)
spec = Gem::Specification.find_by_name("tourist")
gem_root = spec.gem_dir
gem_lib = gem_root + "/lib"
Anemone.crawl(site_address, depth_limit: depth) do |anemone|
i = 0
site_dir = image_location + "/" + site_name
if (!Dir.exist?(image_location))
Dir.mkdir(image_location)
end
Dir.mkdir(site_dir)
anemone.on_every_page do |page|
begin
status = Timeout::timeout(10) {
image_name = page.url.to_s.split("/").last.to_s + "." + page.url.hash.to_s + ".png"
puts `phantomjs #{gem_lib}/rasterize.js #{page.url} #{site_dir}/#{image_name} #{view_width} #{view_height}`
}
rescue Exception => ex
puts ex
end
i=i+1;
end
end
end
|