Skip to content

Instantly share code, notes, and snippets.

@kevinpet
Created April 17, 2009 07:26
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 kevinpet/96900 to your computer and use it in GitHub Desktop.
Save kevinpet/96900 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# http://kdpeterson.net
# Copyright (c) 2009 Kevin Dempsey Peterson
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
require "mysql"
require 'parsedate'
# configure these for your system
MysqlHost = "localhost"
MysqlUser = "root"
MysqlPass = "RIPMtj0T"
MysqlDatabase = "nucleus"
Divider = "-----"
LongDivider = "--------" # for doing "long division"
my = Mysql::new(MysqlHost, MysqlUser, MysqlPass, MysqlDatabase)
res = my.query("select inumber, ititle, itime, ibody, imore, icat from nucleus_item")
entries = Hash.new
while row = res.fetch_hash do
entries[row['inumber']] = row
entries[row['inumber']]
end
res = my.query("select cnumber, cbody, cuser, cmail, citem, cip, ctime from nucleus_comment order by cnumber")
while row = res.fetch_hash do
entries[row['citem']][:comments] ||= []
entries[row['citem']][:comments] << row
end
def fixdate(nucleus_date)
(y, m, d, h, min, s, z, wk) = ParseDate.parsedate nucleus_date
"%02d/%02d/%04d %02d:%02d:%02d" % [m, d, y, h, min, s]
end
entries.each do |k, entry|
puts "TITLE: #{entry['ititle']}"
puts "DATE: #{fixdate entry['itime']}"
puts "PRIMARY CATEGORY: #{entry['icat']}"
puts Divider
puts "BODY:"
puts entry['ibody']
puts Divider
puts "EXTENDED BODY:"
puts entry['imore']
puts Divider
if entry[:comments] then
entry[:comments].each do |comment|
puts "COMMENT:"
puts "AUTHOR: #{comment['cuser']}"
puts "DATE: #{fixdate comment['ctime']}"
puts "IP: #{comment['cip']}"
puts "EMAIL: #{comment['cmail']}"
puts comment['cbody']
puts Divider
end
end
puts LongDivider
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment