# This is to load initial data require 'iconv' require 'config/environment' dir = 'db/ROOT' ICONV = Iconv.new('UTF-8', 'ISO-8859-15') def inputDir(directory) Dir.glob(directory+'/*.txt') do |file| dir = directory+'/'+file inputFile File.basename(directory), file end Dir.foreach(directory) do |d| if (d != '.' and d != '..' and d != '.svn') dir = directory+'/'+d if (File.directory?(dir) or File.symlink?(dir)) #puts 'dir: '+dir inputDir dir end end end end def inputFile(d, fileName) puts 'Loading: '+fileName elt = Elt.find_by_id(File.basename(fileName).gsub(/.txt/, '')) file = File.new(fileName) if elt == nil elt = Elt.new elt.id = File.basename(fileName).gsub(/.txt/, '') elt.created_on = nil end if elt.created_on == nil or elt.created_on < file.mtime elt.mail = nil elt.parent_id = d elt.created_on = file.mtime puts elt.created_on.class elt.subject = ICONV.iconv(file.gets.strip) elt.body = format(ICONV.iconv(file.gets('\n'))) print "subject: "+elt.subject #puts "body: "+elt.body puts " (created_on: "+elt.created_on.to_s+")" elt.save end end inputDir dir