Created
October 2, 2008 13:48
-
-
Save mrsimo/14357 to your computer and use it in GitHub Desktop.
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
def get_images | |
require 'action_controller' | |
require 'action_controller/test_process.rb' | |
require 'mime/types' # gem install mime-types | |
@log = Array.new | |
@posts = WpaPost.find :all | |
@results = Array.new | |
# hacer un bucle recorriendo lo que sea que tiene las posibles imagenes. | |
@posts.each do |p| | |
@results = @results + (p.post_content.scan /src=\"(\S+)\"/) | |
end | |
Dir.chdir('images') do | |
for img in @results | |
`curl -O #{img}` # wget #{img} si estamos en linux | |
image = File.basename(img.to_s) | |
if File.exists? image | |
mimetype = MIME::Types.type_for(image) | |
if p = Photo.create(:uploaded_data => ActionController::TestUploadedFile.new(image,mimetype)) | |
@log << "Imagen #{image} importada" | |
else | |
@log << "Fallo al importar #{image}" | |
end | |
else | |
@log << "La imagen #{img} no se ha podido descargar" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment