public
Fork of bruno/openaustralia-parser
Description: Parser component for Open Australia
Homepage: http://openaustralia.org
Clone URL: git://github.com/mlandauer/openaustralia-parser.git
openaustralia-parser / export-comments.rb
100755 25 lines (17 sloc) 0.847 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/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")