OSDN Git Service

moved
[tdcgexplorer/nimono-crawlers.git] / bin / read-zip.rb
1 #!ruby
2 # encoding: utf-8
3 $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
4 require 'scrap'
5
6 location = ARGV.shift || 'mmd'
7 scrap = Scrap.find_by_location_code(location)
8
9 require 'rubygems'
10 require 'bundler/setup'
11 require 'zipruby'
12 require 'nkf'
13
14 def encode(str)
15   str && NKF.nkf('-Sw', str)
16 end
17
18 def dump_zip(path)
19   Zip::Archive.open(path) do |ar|
20     puts "# #{path}"
21
22     n = ar.num_files # number of entries
23     n.times do |i|
24       entry_name = ar.get_name(i) # get entry name from archive
25
26       # open entry
27       ar.fopen(i) do |f|
28         puts [ f.size, f.comp_size, f.mtime.strftime("%d-%m-%y %H:%M"), encode(f.name) ].join("\t")
29
30         # content = f.read # read entry content
31       end
32     end
33   end
34 rescue Zip::Error => exc
35   puts "error: " + exc.message
36 end
37
38 ent = "/Volumes/uploader/src/#{location}/index.html"
39 open(ent) do |f|
40   while line = f.gets
41     if scrap.match(line)
42       name, = scrap.row
43       dump_zip("/Volumes/uploader/arc/#{location}/#{name}")
44       puts
45     end
46   end
47 end