Skip to content

Instantly share code, notes, and snippets.

@hayeah
Last active December 18, 2015 17:49
Show Gist options
  • Save hayeah/5821472 to your computer and use it in GitHub Desktop.
Save hayeah/5821472 to your computer and use it in GitHub Desktop.
link images downloaded by exporter into img2
# files = `find /pf/puffant/images/member_photos/ -links 1`.split "n" ; 3
files = Dir["/pf/puffant/images/member_photos/**/*_o.*"]
files.each_slice(1000) do |ff|
link_files(ff)
end
def img_ids(files)
ids = files.map { |file|
name = File.basename(file)
img_id = name.split("_")[0].to_i
}
end
def img_records(ids)
Puffant::MemberPhoto.where(:id => ids)
end
def link_files(files)
ids = img_ids(files)
imgs = img_records(ids)
id_to_img = imgs.inject({}) do |h,img|
h[img.id] = img
h
end
files.each do |file|
name = File.basename(file)
id = name.split("_")[0].to_i
img = id_to_img[id]
next if img.nil?
next if img.loc != 2
from = file
to = "/pf/puffant-img-2/member_photos/#{img.account_id}/#{name}"
cmd = "ln #{from} #{to}"
puts cmd
system cmd
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment