Skip to content

Instantly share code, notes, and snippets.

@robsalasco
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robsalasco/58b2fbaed7020a0a6edb to your computer and use it in GitHub Desktop.
Save robsalasco/58b2fbaed7020a0a6edb to your computer and use it in GitHub Desktop.
Las Ultimas Noticias (lun.com) - swf to pdf converter
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