Created
July 8, 2012 14:16
-
-
Save miio/3071158 to your computer and use it in GitHub Desktop.
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
def crawl | |
FlickRaw.api_key = "♥♥♥♥♥♥♥♥♥♥♥♥♥♥" | |
FlickRaw.shared_secret = "♥♥♥♥♥♥♥♥♥♥♥♥♥♥" | |
flickr.access_token = "♥♥♥♥♥♥♥♥♥♥♥♥♥♥-♥♥♥♥♥♥♥♥♥♥♥♥♥♥" | |
flickr.access_secret = "♥♥♥♥♥♥♥♥♥♥♥♥♥♥" | |
login = flickr.test.login | |
list = flickr.people.getPhotos :user_id => login.id | |
file = "" | |
info = [] | |
Photo.transaction do | |
list.each do |l| | |
info = PhotoGroup.find_by_flickr_id l.id | |
unless info | |
info = flickr.photos.getInfo :photo_id => l.id, :secret => l.secret | |
open "#{Rails.root}/storage/#{File.basename FlickRaw.url_z info }", "wb" do |file| | |
open FlickRaw.url_z info do |data| | |
file.write data.read | |
end | |
end | |
# Set Photo | |
p = Photo.new :title => info.title, :content_type => 'image/jpeg' | |
p.save! | |
# Set Thumbnail and PhotoGroups | |
g = PhotoGroup.new :thumbnail_id => p.id, :flickr_id => l.id | |
g.save! | |
else | |
info = Photo.find_by_id l.id | |
end | |
file += "/#{l.id}<br />" | |
end | |
end | |
respond_to do |format| | |
format.html { render :text => file } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
あっちこっち行き当たりばったりなことしすぎたので、無駄な処理系のこってます