辛苦写了一下午,贡献给大家。。。不知道怎么贴代码
<code>
require 'net/http'
require 'digest'
desc "fetch avatar from
http://www.v2ex.com/"
task :fetch_avatar do
prefix = 'images/'
(1..50000).each do |idx|
puts "process id = " + idx.to_s + "\n"
md5 = Digest::MD5.hexdigest(idx.to_s)
remote_dir = md5[0,4] + '/' + md5[4,4] + '/'
local_dir = prefix + remote_dir
FileUtils.mkdir_p local_dir if ! Dir.exists? local_dir
remote_filename = remote_dir + idx.to_s + '_large.png'
local_filename = prefix + remote_filename
next if File.exists? local_filename
url = '
http://cdn.v2ex.com/avatar/' + remote_filename
IO.binwrite(local_filename, Net::HTTP.get(URI(url)))
end
end
</code>