OSDN Git Service

47838bf5ca2acbbe7ed0a10d7ff140e098eb15bf
[tdcgexplorer/nimono-crawlers.git] / bin / load-arcs.rb
1 #!ruby
2 # vim: fileencoding=utf-8
3 $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
4 require 'connection'
5 require 'location'
6 require 'arc'
7
8 location_code = ARGV.shift || 'mmd'
9 location = Location.find_by_code(location_code)
10 unless location
11   puts "location not found."
12   exit
13 end
14
15 while line = gets
16   case location.code
17   when 'mmd'
18     name, summary, size, date, mime, origname, with_key, with_password = line.chomp.split(/\t/)
19   when 'mmdfile', 'mmdacc1', 'mmdacc2'
20     name, summary, size, date, origname = line.chomp.split(/\t/)
21   end
22   md = /\.(.+)\z/.match(name)
23   extname = md[1]
24   code = File.basename(name, '.' + extname)
25   case location.code
26   when 'mmd'
27     #
28   when 'mmdfile'
29     code = 'file%04d' % code.to_i
30   when 'mmdacc1'
31     code = 'mini%04d' % code.to_i
32   when 'mmdacc2'
33     code = code[3..-1]
34   end
35   arc = Arc.find_by_code(code)
36   if arc
37     puts "found code: #{code}"
38     next
39   end
40   puts "Arc.create code: #{code}"
41   arc = Arc.create(:code => code, :extname => extname, :location => location, :summary => summary, :origname => origname)
42 end