forked from openaustralia/openaustralia-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport-comments.rb
More file actions
executable file
·24 lines (17 loc) · 847 Bytes
/
export-comments.rb
File metadata and controls
executable file
·24 lines (17 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env ruby
$:.unshift "#{File.dirname(__FILE__)}/lib"
require 'environment'
require 'configuration'
require 'mysql'
require 'csv'
conf = Configuration.new
db = Mysql.real_connect(conf.database_host, conf.database_user, conf.database_password, conf.database_name)
res = db.query("select comments.*, comments.body as comment_body, epobject.body as hansard_body, hdate from comments, epobject, hansard where hansard.epobject_id = epobject.epobject_id and comments.epobject_id = epobject.epobject_id")
outfile = File.open('exported-comments.csv', 'wb')
CSV::Writer.generate(outfile) do |csv|
res.each_hash do |row|
csv << [row["comment_id"], row["user_id"], row["visible"], row["modflagged"], row["posted"], row["hdate"], row["comment_body"], row["hansard_body"][0..300]]
end
end
outfile.close
db.query("DELETE FROM comments")