Sha256: f7e9923b68868fd8c5a6bfa00f70b687df1fd9d1f3e048d78c7930cd0df59c46
Contents?: true
Size: 1.95 KB
Versions: 6
Compression:
Stored size: 1.95 KB
Contents
#!/usr/bin/env ruby # MovableType export-file importer for typo by Scott Laird <scott@sigkill.org> # # MAKE BACKUPS OF EVERYTHING BEFORE RUNNING THIS SCRIPT! # THIS SCRIPT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND require File.dirname(__FILE__) + '/../../config/environment' def import_comment(article, c, filter) comment = Comment.new article.comments << comment comment.ip = c[:ip] comment.body = c[:comment].to_s comment.author = c[:author] comment.email = c[:email] comment.url = c[:url] comment.created_at = c[:date] comment.text_filter = filter comment.published = true comment.save end def get_user(name) User.find_by_name(name) || User.create(:name => name, :password => 'foobar') end def get_category(name) Category.find_by_name(name) || Category.create(:name => name) end file = ARGV[0] data = File.read(file) STDERR.puts "Read #{data.size} bytes from #{file}" import = eval(data) filter = TextFilter.find_by_name('markdown smartypants') STDERR.puts "Extracted #{import.size} entries" import.each do |a| STDERR.puts "Working with article '#{a[:title]}'" # STDERR.puts YAML.dump(a) article = Article.new article.title = a[:title] article.keywords = a[:keywords] article.allow_comments = a[:allow_comments] == '1' article.allow_pings = a[:allow_pings] == '1' article.created_at = a[:date] article.excerpt = a[:excerpt] article.body = a[:body].to_s article.extended = a[:extended_body].to_s article.published = a[:status] == 'Publish' article.text_filter = filter article.author = a[:author] article.user = get_user(a[:author]) article.save if a[:comment].kind_of? Hash import_comment(article,a[:comment],filter) article.comments_count = 1 elsif a[:comment].kind_of? Array a[:comment].each do |c| import_comment(article,c,filter) end article.comments_count = a[:comment].size end a[:category].to_a.each {|category| article.categories << get_category(category)} article.save end
Version data entries
6 entries across 6 versions & 1 rubygems