Current location

narf Source control manager Git

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshtrom <shtrom@1991c358-8f32-0410-a49a-990740bdf4c2>2014-04-23 01:29:09 +0000
committershtrom <shtrom@1991c358-8f32-0410-a49a-990740bdf4c2>2014-04-23 01:29:09 +0000
commita84460024f4da0312d277121926867f8e549938d (patch)
tree174f8ed78a9224a456651fc3fc487a41d4bef726 /Blogsum2WP.rb
parent2b3d190da9dda8d60be9f0bb49bdfd6b651a41c7 (diff)
[Blogsum2WP] Add some comments for public consumption
git-svn-id: svn+ssh://scm.narf.ssji.net/svn/shtrom/scripts@1814 1991c358-8f32-0410-a49a-990740bdf4c2
Diffstat (limited to 'Blogsum2WP.rb')
-rwxr-xr-xBlogsum2WP.rb49
1 files changed, 47 insertions, 2 deletions
diff --git a/Blogsum2WP.rb b/Blogsum2WP.rb
index c4b542c..328fcc0 100755
--- a/Blogsum2WP.rb
+++ b/Blogsum2WP.rb
@@ -1,4 +1,35 @@
#!/usr/bin/env ruby19
+#
+# A quick and dirty script to import posts, comments and tags from Blogsum into
+# Wordpress
+# Copyright (c) 2014, Olivier Mehani <shtrom@ssji.net>
+# All rights reserved.
+#
+# $Id: bsdnotice.ab.c 799 2010-05-26 01:07:56Z shtrom $
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# 3. Neither the name of Olivier Mehani nor the names of its contributors
+# may be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
require 'rubygems'
require 'yaml'
@@ -6,9 +37,8 @@ require 'active_record'
require 'sqlite3'
require 'mysql'
+## Databases to use
-# Models generated by RMRE [0]
-# [0] https://github.com/bosko/rmre
settings_file = './database.yml'
# The yaml file should look like that
#
@@ -26,6 +56,13 @@ settings_file = './database.yml'
exit unless File.exists?(settings_file)
$settings = YAML.load_file(settings_file)
+
+## ActiveRecord models
+
+# Models generated by RMRE [0], then manually extended to capture missed
+# relationships
+# [0] https://github.com/bosko/rmre
+
# Blogsum
class Article < ActiveRecord::Base
establish_connection $settings["blogsum"]
@@ -89,8 +126,12 @@ class WpUser < ActiveRecord::Base
has_many :wp_comments, foreign_key: :user_id
end
+
+## Some sanity checks
+
# Blogsum
#puts Article.find(1).title
+# I know this article has a comment
#puts Article.find(3).comment[0].comment
#Wordpress
@@ -98,8 +139,12 @@ end
#puts WpPost.find(1).wp_user.user_login
#puts WpPost.find(1).wp_comments[0].comment_content
#puts WpPost.find(1).wp_term_taxonomy
+# I know this article has tags
#puts WpPost.find(7).wp_terms.map {|t| "#{t.name}, "}
+
+## Do the import for real!
+
Article.all.each do |a|
print "P #{a.title} #{a.date} #{a.author} #{a.uri} #{a.tags} #{a.body[0..19]}\n"
u = WpUser.find_by_user_login(a.author) || WpUser.all[0] # Map unknown users to admin