Last active
August 29, 2015 14:02
-
-
Save robsalasco/58b2fbaed7020a0a6edb to your computer and use it in GitHub Desktop.
Las Ultimas Noticias (lun.com) - swf to pdf converter
This file contains 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' | |
time = Time.now.strftime("%Y-%m-%d") | |
match = open("http://www.lun.com/pages/LUNHomepage.aspx?BodyID=0&dt=" + time).read.scan(/(http\:\/\/images\.lun\.com\/luncontents\/NewsPaperPages\/.*\.swf)/).flatten | |
puts "Creando directorio temporal de descarga" | |
FileUtils.mkdir("/tmp/lun/") | |
match.each do |entry| | |
open("/tmp/lun/" + 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/lun/'#{File.basename(entry)}' -o /tmp/lun/'#{File.basename(entry, '.swf')}'.png") | |
puts "Quitando " + File.basename(entry) | |
FileUtils.rm("/tmp/lun/" + File.basename(entry)) | |
end | |
end | |
end | |
filenames = match.map { |f| "/tmp/lun/" + File.basename(f, '.swf') + ".png" } | |
puts "Generando LUN_#{time}.pdf" | |
system("convert #{filenames.join(' ')} LUN_#{time}.pdf") | |
puts "Quitando directorio temporal" | |
FileUtils.rm_rf("/tmp/lun/") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment