Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/ruby
- require 'rubygems'
- require 'active_record'
- i = 0
- ido1 = Time.now
- ActiveRecord::Base.establish_connection(
- :adapter => 'postgresql',
- :database => 'wiki',
- :username => 'wiki',
- :password => 'lool',
- :host => '127.1.0.2')
- #ActiveRecord::Base.logger = Logger.new(STDERR)
- ActiveRecord::Base.pluralize_table_names = false
- class Wiki < ActiveRecord::Base
- set_table_name "wiki"
- end
- begin
- file = File.open("wiki.xml", "r")
- while (line = file.readline)
- title = line.gsub(/<title[^>]*>/, '')..gsub(/<\/title>/, '') if line =~ /title/
- text = line.gsub(/<text[^>]*>/, '').gsub(/<\/text>/, '') if line =~ /text/
- if line =~ /\/page/
- page= Wiki.create(:title => title, :text => text)
- i = i + 1
- end
- if i == 1000
- kul = (Time.now - ido1)
- puts "#{kul.to_s} secundum, #{1000/kul} row/s"
- ido1 = Time.now
- i = 0
- end
- end
- rescue EOFError
- file.close
- end
Add Comment
Please, Sign In to add comment