0
我在Heroku/Ruby Sinatra中構建了一個Web工具,用於刮取Web域並下載所有指定的文件類型(它應該提供要下載的域的文件類型的站點地圖的zip文件) 。在Heroku中構建可下載的站點地圖zip文件
我想弄清楚如何在Heroku上構建ZipFile。我如何設置主目錄?然後,一旦我有ZipFile,我如何鏈接到它,所以它是可下載的?
下面是一些relavent代碼至今:
anemone.after_crawl do
puts "Crawl finished. Gathering files, preparing download..."
datasets.each do |url|
u = URI.parse(url.to_s)
Net::HTTP.start(u.host) { |http|
resp = http.get(u.path)
if u.path[0] == "/"
u.path[0] = ''
end
full_path = u.path.split("/")
i = 0
len = full_path.size
filename = full_path[-1]
Zip::ZipFile.open(u.host + ".zip", Zip::ZipFile::CREATE) {
|zipfile|
while i < (len-1) do
directory = full_path[i]
unless File.directory?(directory)
zipfile.mkdir(directory)
end
Dir.chdir directory
i+=1
end
zipfile.add(filename);
while (i > 0) do
Dir.chdir File.expand_path("..",Dir.pwd)
i-=1
end
}
}
end
end
謝謝你,我很感激。 – dbuss1