Created
June 24, 2014 21:16
-
-
Save robsalasco/c7ab7d9b2f033cab7381 to your computer and use it in GitHub Desktop.
El Mercurio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
require 'fileutils.rb' | |
cuerpo = {"Cuerpo A" => 1, "Cuerpo B" => 2, "Cuerpo C" => 3, "Cuerpo D" => 4, "Cuerpo E" => 5, "Cuerpo F" => 6} | |
def cuerpodown(cuerpo) | |
time = Time.now.strftime("%Y-%m-%d") | |
match = open("http://impresa.elmercurio.com/pages/LUNHomepage.aspx?BodyID=" + cuerpo + "&dt=" + time + "&dtB=" + time + "&dtB=" + time).read.scan(/(http\:\/\/images\.elmercurio\.com\/MerServerContents\/NewsPaperPages\/.*\.swf)/).flatten | |
match.each do |entry| | |
open("/tmp/elmercurio/" + File.basename(entry), "wb") do |file| | |
open(entry) do |uri| | |
puts "Descargando " + File.basename(entry) | |
file.write(uri.read) | |
puts "Generando imagen " + File.basename(entry, '.swf') + ".png" | |
system("swfrender /tmp/elmercurio/'#{File.basename(entry)}' -o /tmp/elmercurio/'#{File.basename(entry, '.swf')}'.png") | |
puts "Quitando " + File.basename(entry) | |
FileUtils.rm("/tmp/elmercurio/" + File.basename(entry)) | |
end | |
end | |
end | |
filenames = match.map { |f| "/tmp/elmercurio/" + File.basename(f, '.swf') + ".png" } | |
puts "Generando ELMERCURIO_cuerpo#{cuerpo}_#{time}.pdf" | |
system("convert #{filenames.join(' ')} ELMERCURIO_cuerpo#{cuerpo}_#{time}.pdf") | |
puts "Limpiando" | |
FileUtils.rm(Dir.glob('/tmp/elmercurio/*.png')) | |
end | |
puts "Creando directorio temporal de descarga" | |
FileUtils.mkdir("/tmp/elmercurio/") | |
cuerpo.each do |key, cuerpo| | |
puts "Descargando #{key}" | |
cuerpodown(cuerpo.to_s) | |
end | |
puts "Quitando directorio temporal" | |
FileUtils.rm_rf("/tmp/elmercurio/") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment