Guest User

Untitled

a guest
Mar 1st, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. require 'rubygems'
  2. require_gem 'activerecord'
  3.  
  4. ActiveRecord::Base.establish_connection(
  5. :adapter => "mysql",
  6. :database => "awong",
  7. :socket => "/var/run/mysqld/mysqld.sock",
  8. :username => 'awong',
  9. :password => 'passwordherelawl'
  10. )
  11. class Wiki_categories < ActiveRecord::Base
  12. set_table_name 'wiki_categories'
  13. set_primary_key 'id'
  14. end
  15.  
  16. class Wiki_articles < ActiveRecord::Base
  17. set_table_name 'wiki_articles'
  18. set_primary_key 'id'
  19. end
  20.  
  21. past_c_ids = []
  22. info = File.new("kate_cat", "r")
  23. c = Wiki_categories.new
  24. a = Wiki_articles.new
  25. while (line = info.readline)
  26. infos = line.split("|")
  27. if (!past_c_ids.include?(infos[0]))
  28. past_c_ids.push(infos[0])
  29. c.category_id = infos[0]
  30. c.category_title = infos[1]
  31. c.save
  32. end
  33. id = infos[2]
  34. title = infos[3].gsub(/\"/, '')
  35. #puts "Id: " + id+ " Title: " + title
  36. a.article_id = id.to_i
  37. a.article_title = title
  38. a.save
  39. end
Add Comment
Please, Sign In to add comment