Guest User

Untitled

a guest
Apr 11th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #!/usr/local/bin/ruby
  2.  
  3. require 'rubygems'
  4. require 'active_record'
  5.  
  6. i = 0
  7. ido1 = Time.now
  8.  
  9. ActiveRecord::Base.establish_connection(
  10. :adapter => 'postgresql',
  11. :database => 'wiki',
  12. :username => 'wiki',
  13. :password => 'lool',
  14. :host => '127.1.0.2')
  15.  
  16. #ActiveRecord::Base.logger = Logger.new(STDERR)
  17. ActiveRecord::Base.pluralize_table_names = false
  18. class Wiki < ActiveRecord::Base
  19. set_table_name "wiki"
  20. end
  21.  
  22. begin
  23. file = File.open("wiki.xml", "r")
  24. while (line = file.readline)
  25. title = line.gsub(/<title[^>]*>/, '')..gsub(/<\/title>/, '') if line =~ /title/
  26. text = line.gsub(/<text[^>]*>/, '').gsub(/<\/text>/, '') if line =~ /text/
  27. if line =~ /\/page/
  28. page= Wiki.create(:title => title, :text => text)
  29. i = i + 1
  30. end
  31. if i == 1000
  32. kul = (Time.now - ido1)
  33. puts "#{kul.to_s} secundum, #{1000/kul} row/s"
  34. ido1 = Time.now
  35. i = 0
  36. end
  37. end
  38. rescue EOFError
  39. file.close
  40. end
Add Comment
Please, Sign In to add comment