Permalink
Browse files

Clean up migrators formatting.

  • Loading branch information...
1 parent a428ace commit aa0d82fa9679843e4356aacd7cb737bb98f16ba3 @mojombo mojombo committed May 8, 2011
@@ -1,7 +1,7 @@
module Jekyll
module CSV
- #Reads a csv with title, permalink, body, published_at, and filter.
- #It creates a post file for each row in the csv
+ # Reads a csv with title, permalink, body, published_at, and filter.
+ # It creates a post file for each row in the csv
def self.process(file = "posts.csv")
FileUtils.mkdir_p "_posts"
posts = 0
@@ -23,4 +23,4 @@ def self.process(file = "posts.csv")
"Created #{posts} posts!"
end
end
-end
+end
@@ -11,12 +11,18 @@
module Jekyll
module Drupal
-
- # Reads a MySQL database via Sequel and creates a post file for each
- # post in wp_posts that has post_status = 'publish'.
- # This restriction is made because 'draft' posts are not guaranteed to
- # have valid dates.
- QUERY = "SELECT node.nid, node.title, node_revisions.body, node.created, node.status FROM node, node_revisions WHERE (node.type = 'blog' OR node.type = 'story') AND node.vid = node_revisions.vid"
+ # Reads a MySQL database via Sequel and creates a post file for each post
+ # in wp_posts that has post_status = 'publish'. This restriction is made
+ # because 'draft' posts are not guaranteed to have valid dates.
+ QUERY = "SELECT node.nid, \
+ node.title, \
+ node_revisions.body, \
+ node.created, \
+ node.status \
+ FROM node, \
+ node_revisions \
+ WHERE (node.type = 'blog' OR node.type = 'story') \
+ AND node.vid = node_revisions.vid"
def self.process(dbname, user, pass, host = 'localhost')
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
@@ -3,7 +3,6 @@
module Jekyll
module Marley
-
def self.regexp
{ :id => /^\d{0,4}-{0,1}(.*)$/,
:title => /^#\s*(.*)\s+$/,
@@ -36,11 +36,22 @@ def self.postgres(c)
# This query will pull blog posts from all entries across all blogs. If
# you've got unpublished, deleted or otherwise hidden posts please sift
# through the created posts to make sure nothing is accidently published.
-
- QUERY = "SELECT id, permalink, body, published_at, title FROM contents WHERE user_id = 1 AND type = 'Article' AND published_at IS NOT NULL ORDER BY published_at"
+ QUERY = "SELECT id, \
+ permalink, \
+ body, \
+ published_at, \
+ title \
+ FROM contents \
+ WHERE user_id = 1 AND \
+ type = 'Article' AND \
+ published_at IS NOT NULL \
+ ORDER BY published_at"
def self.process(dbname, user, pass, host = 'localhost')
- db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
+ db = Sequel.mysql(dbname, :user => user,
+ :password => pass,
+ :host => host,
+ :encoding => 'utf8')
FileUtils.mkdir_p "_posts"
@@ -49,16 +60,10 @@ def self.process(dbname, user, pass, host = 'localhost')
slug = post[:permalink]
date = post[:published_at]
content = post[:body]
-# more_content = ''
-
- # Be sure to include the body and extended body.
-# if more_content != nil
-# content = content + " \n" + more_content
-# end
- # Ideally, this script would determine the post format (markdown, html
- # , etc) and create files with proper extensions. At this point it
- # just assumes that markdown will be acceptable.
+ # Ideally, this script would determine the post format (markdown,
+ # html, etc) and create files with proper extensions. At this point
+ # it just assumes that markdown will be acceptable.
name = [date.year, date.month, date.day, slug].join('-') + ".markdown"
data = {
View
@@ -18,7 +18,14 @@ module MT
# This query will pull blog posts from all entries across all blogs. If
# you've got unpublished, deleted or otherwise hidden posts please sift
# through the created posts to make sure nothing is accidently published.
- QUERY = "SELECT entry_id, entry_basename, entry_text, entry_text_more, entry_authored_on, entry_title, entry_convert_breaks FROM mt_entry"
+ QUERY = "SELECT entry_id, \
+ entry_basename, \
+ entry_text, \
+ entry_text_more, \
+ entry_authored_on, \
+ entry_title, \
+ entry_convert_breaks \
+ FROM mt_entry"
def self.process(dbname, user, pass, host = 'localhost')
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
@@ -38,17 +45,18 @@ def self.process(dbname, user, pass, host = 'localhost')
content = content + " \n" + more_content
end
- # Ideally, this script would determine the post format (markdown, html
- # , etc) and create files with proper extensions. At this point it
- # just assumes that markdown will be acceptable.
- name = [date.year, date.month, date.day, slug].join('-') + '.' + self.suffix(entry_convert_breaks)
+ # Ideally, this script would determine the post format (markdown,
+ # html, etc) and create files with proper extensions. At this point
+ # it just assumes that markdown will be acceptable.
+ name = [date.year, date.month, date.day, slug].join('-') + '.' +
+ self.suffix(entry_convert_breaks)
data = {
'layout' => 'post',
'title' => title.to_s,
'mt_id' => post[:entry_id],
'date' => date
- }.delete_if { |k,v| v.nil? || v == ''}.to_yaml
+ }.delete_if { |k,v| v.nil? || v == '' }.to_yaml
File.open("_posts/#{name}", "w") do |f|
f.puts data
@@ -60,17 +68,18 @@ def self.process(dbname, user, pass, host = 'localhost')
def self.suffix(entry_type)
if entry_type.nil? || entry_type.include?("markdown")
- # The markdown plugin I have saves this as "markdown_with_smarty_pants", so I just look for "markdown".
- "markdown"
- elsif entry_type.include?("textile")
- # This is saved as "textile_2" on my installation of MT 5.1.
- "textile"
- elsif entry_type == "0" || entry_type.include?("richtext")
- # richtext looks to me like it's saved as HTML, so I include it here.
- "html"
- else
- # Other values might need custom work.
- entry_type
+ # The markdown plugin I have saves this as
+ # "markdown_with_smarty_pants", so I just look for "markdown".
+ "markdown"
+ elsif entry_type.include?("textile")
+ # This is saved as "textile_2" on my installation of MT 5.1.
+ "textile"
+ elsif entry_type == "0" || entry_type.include?("richtext")
+ # Richtext looks to me like it's saved as HTML, so I include it here.
+ "html"
+ else
+ # Other values might need custom work.
+ entry_type
end
end
end
@@ -9,44 +9,41 @@
module Jekyll
module Posterous
-
def self.fetch(uri_str, limit = 10)
# You should choose better exception.
raise ArgumentError, 'Stuck in a redirect loop. Please double check your email and password' if limit == 0
-
+
response = nil
- Net::HTTP.start('posterous.com') {|http|
+ Net::HTTP.start('posterous.com') do |http|
req = Net::HTTP::Get.new(uri_str)
req.basic_auth @email, @pass
response = http.request(req)
- }
+ end
case response
when Net::HTTPSuccess then response
when Net::HTTPRedirection then fetch(response['location'], limit - 1)
else response.error!
end
end
-
-
+
def self.process(email, pass, blog = 'primary')
@email, @pass = email, pass
@api_token = JSON.parse(self.fetch("/api/2/auth/token").body)['api_token']
FileUtils.mkdir_p "_posts"
-
+
posts = JSON.parse(self.fetch("/api/v2/users/me/sites/#{blog}/posts?api_token=#{@api_token}").body)
page = 1
-
+
while posts.any?
-
posts.each do |post|
title = post["title"]
- slug = title.gsub(/[^[:alnum:]]+/, '-').downcase
+ slug = title.gsub(/[^[:alnum:]]+/, '-').downcase
date = Date.parse(post["display_date"])
content = post["body_html"]
published = !post["is_private"]
name = "%02d-%02d-%02d-%s.html" % [date.year, date.month, date.day, slug]
-
+
# Get the relevant fields as a hash, delete empty fields and convert
# to YAML for the header
data = {
@@ -61,13 +58,11 @@ def self.process(email, pass, blog = 'primary')
f.puts "---"
f.puts content
end
-
end
-
+
page += 1
- posts = JSON.parse(self.fetch("/api/v2/users/me/sites/#{blog}/posts?api_token=#{@api_token}&page=#{page}").body)
+ posts = JSON.parse(self.fetch("/api/v2/users/me/sites/#{blog}/posts?api_token=#{@api_token}&page=#{page}").body)
end
-
end
end
-end
+end
@@ -11,18 +11,25 @@
module Jekyll
module TextPattern
# Reads a MySQL database via Sequel and creates a post file for each post.
- # The only posts selected are those with a status of 4 or 5, which means "live"
- # and "sticky" respectively.
- # Other statuses is 1 => draft, 2 => hidden and 3 => pending
- QUERY = "select Title, url_title, Posted, Body, Keywords from textpattern where Status = '4' or Status = '5'"
+ # The only posts selected are those with a status of 4 or 5, which means
+ # "live" and "sticky" respectively.
+ # Other statuses are 1 => draft, 2 => hidden and 3 => pending.
+ QUERY = "SELECT Title, \
+ url_title, \
+ Posted, \
+ Body, \
+ Keywords \
+ FROM textpattern \
+ WHERE Status = '4' OR \
+ Status = '5'"
def self.process(dbname, user, pass, host = 'localhost')
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
FileUtils.mkdir_p "_posts"
db[QUERY].each do |post|
- # Get required fields and construct Jekyll compatible name
+ # Get required fields and construct Jekyll compatible name.
title = post[:Title]
slug = post[:url_title]
date = post[:Posted]
@@ -31,14 +38,14 @@ def self.process(dbname, user, pass, host = 'localhost')
name = [date.strftime("%Y-%m-%d"), slug].join('-') + ".textile"
# Get the relevant fields as a hash, delete empty fields and convert
- # to YAML for the header
+ # to YAML for the header.
data = {
'layout' => 'post',
'title' => title.to_s,
'tags' => post[:Keywords].split(',')
}.delete_if { |k,v| v.nil? || v == ''}.to_yaml
- # Write out the data and content to file
+ # Write out the data and content to file.
File.open("_posts/#{name}", "w") do |f|
f.puts data
f.puts "---"
@@ -47,4 +54,4 @@ def self.process(dbname, user, pass, host = 'localhost')
end
end
end
-end
+end
@@ -5,8 +5,8 @@
module Jekyll
module Typo
- # this SQL *should* work for both MySQL and PostgreSQL, but I haven't
- # tested PostgreSQL yet (as of 2008-12-16)
+ # This SQL *should* work for both MySQL and PostgreSQL, but I haven't
+ # tested PostgreSQL yet (as of 2008-12-16).
SQL = <<-EOS
SELECT c.id id,
c.title title,
@@ -30,8 +30,9 @@ def self.process dbname, user, pass, host='localhost'
sprintf("%.02d", post[:date].month),
sprintf("%.02d", post[:date].day),
post[:slug].strip ].join('-')
+
# Can have more than one text filter in this field, but we just want
- # the first one for this
+ # the first one for this.
name += '.' + post[:filter].split(' ')[0]
File.open("_posts/#{name}", 'w') do |f|
@@ -45,5 +46,5 @@ def self.process dbname, user, pass, host='localhost'
end
end
- end # module Typo
-end # module Jekyll
+ end
+end
@@ -11,20 +11,27 @@
module Jekyll
module WordPress
-
def self.process(dbname, user, pass, host = 'localhost', table_prefix = 'wp_')
db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8')
- FileUtils.mkdir_p "_posts"
-
+ FileUtils.mkdir_p("_posts")
+
# Reads a MySQL database via Sequel and creates a post file for each
- # post in wp_posts that has post_status = 'publish'.
- # This restriction is made because 'draft' posts are not guaranteed to
- # have valid dates.
- query = "select post_title, post_name, post_date, post_content, post_excerpt, ID, guid from #{table_prefix}posts where post_status = 'publish' and post_type = 'post'"
+ # post in wp_posts that has post_status = 'publish'. This restriction is
+ # made because 'draft' posts are not guaranteed to have valid dates.
+ query = "SELECT post_title, \
+ post_name, \
+ post_date, \
+ post_content, \
+ post_excerpt, \
+ ID, \
+ guid \
+ FROM #{table_prefix}posts \
+ WHERE post_status = 'publish' AND \
+ post_type = 'post'"
db[query].each do |post|
- # Get required fields and construct Jekyll compatible name
+ # Get required fields and construct Jekyll compatible name.
title = post[:post_title]
slug = post[:post_name]
date = post[:post_date]
@@ -33,15 +40,15 @@ def self.process(dbname, user, pass, host = 'localhost', table_prefix = 'wp_')
slug]
# Get the relevant fields as a hash, delete empty fields and convert
- # to YAML for the header
+ # to YAML for the header.
data = {
'layout' => 'post',
'title' => title.to_s,
'excerpt' => post[:post_excerpt].to_s,
'wordpress_id' => post[:ID],
'wordpress_url' => post[:guid],
'date' => date
- }.delete_if { |k,v| v.nil? || v == ''}.to_yaml
+ }.delete_if { |k,v| v.nil? || v == '' }.to_yaml
# Write out the data and content to file
File.open("_posts/#{name}", "w") do |f|
@@ -50,7 +57,6 @@ def self.process(dbname, user, pass, host = 'localhost', table_prefix = 'wp_')
f.puts content
end
end
-
end
end
end
Oops, something went wrong.

0 comments on commit aa0d82f

Please sign in to comment.