Skip to content

Instantly share code, notes, and snippets.

@masui
Created January 26, 2013 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masui/4640928 to your computer and use it in GitHub Desktop.
Save masui/4640928 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'logger'
require 'active_record'
# ActiveRecord::Base.logger = Logger.new(STDERR)
# ActiveRecord::Base.colorize_logging = false
if File.exist?("3memo.sqlite3") then
File.delete("3memo.sqlite3")
end
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => '3memo.sqlite3'
)
ActiveRecord::Schema.define do
create_table :entries do |table|
table.column :key, :text
table.column :url, :text
table.column :date, :text
table.column :title, :text
end
end
class Entry < ActiveRecord::Base
end
File.open("3memo.txt"){ |f|
f.each { |line|
line.chomp!
(key,url,date,title) = line.split(/\t/);
Entry.create(
:key => key,
:url => url,
:date => date,
:title => title
)
}
}
entries = Entry.find(:all)
entries.each { |entry|
puts entry.title
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment