Sha256: 5b2cecea5c60391700802d3d0252d035276f9cb5047cfd1901c82c112545995d

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 KB

Contents

# 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: '+File.basename(fileName).gsub(/.txt/, '')

	elt = Elt.find_by_id File.basename(fileName).gsub(/.txt/, '')
	elt ||= Elt.new :id => File.basename(fileName).gsub(/.txt/, ''), :created_on => nil

	file = File.new fileName

	if !elt.created_on 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')))
		puts "subject: #{elt.subject} (created_on: #{elt.created_on.to_s})"
		elt.save
		elt.parent.add_child elt unless elt.lft or elt.rgt
	end
end

inputDir dir

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
parlement-0.10 lib/data_import.rb
parlement-0.11 lib/data_import.rb
parlement-0.12 lib/data_import.rb
parlement-0.13 lib/data_import.rb
parlement-0.14 lib/data_import.rb
parlement-0.17 lib/data_import.rb
parlement-0.8 lib/data_import.rb
parlement-0.9 lib/data_import.rb