OSDN Git Service

61fd0f186122bab247402d66b60eeaa612489f69
[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   name, summary, size, date, origname = line.chomp.split(/\t/)
17   md = /\.(.+)\z/.match(name)
18   extname = md[1]
19   code = File.basename(name, '.' + extname)
20   case location.code
21   when 'mmd'
22     #
23   when 'mmdfile'
24     code = 'file%04d' % code.to_i
25   when 'mmdacc1'
26     code = 'mini%04d' % code.to_i
27   when 'mmdacc2'
28     code = code[3..-1]
29   end
30   arc = Arc.find_by_code(code)
31   if arc
32     puts "found code: #{code}"
33     next
34   end
35   puts "Arc.create code: #{code}"
36   arc = Arc.create(:code => code, :extname => extname, :location => location, :summary => summary, :origname => origname)
37 end