Skip to content

Instantly share code, notes, and snippets.

@ariejan
Created March 22, 2010 20:02
Show Gist options
  • Save ariejan/340474 to your computer and use it in GitHub Desktop.
Save ariejan/340474 to your computer and use it in GitHub Desktop.
### SQL
# Use the below query in Sequel Pro => Export to XML
#
# This includes tags, not categories
#
# SELECT p.ID, p.post_date, p.post_content, p.post_title, p.post_name, GROUP_CONCAT(t.name SEPARATOR ', ') AS tags
# FROM wp_posts p
# LEFT JOIN wp_term_relationships tr ON tr.object_id = p.id
# LEFT JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
# LEFT JOIN wp_terms t ON tt.term_id = t.term_id
# WHERE post_status = 'publish'
# AND post_parent = 0
# AND post_author = 2
# AND post_type = 'post'
# GROUP BY p.ID;
## Run in 'articles' directory:
# ruby ~/Desktop/migrate.rb
require 'rubygems'
require 'nokogiri'
doc = Nokogiri::XML(open("/Users/ariejan/Desktop/ajn.xml"))
doc.xpath("//custom/row").each do |row|
title = row.xpath('post_title').text
puts "Processing: #{title}"
author = "Ariejan de Vroom"
slug = row.xpath('post_name').text
content = row.xpath('post_content').text
pub_date = Time.parse(row.xpath('post_date').text)
tags = row.xpath('tags').text
File.open("#{pub_date.strftime("%Y-%m-%d")}-#{slug}.textile", "w") do |f|
f.write("---\n")
f.write("title: \"#{title}\"\n")
f.write("author: #{author}\n")
f.write("date: #{pub_date.strftime("%Y/%m/%d")}\n")
f.write("slug: #{slug}\n")
f.write("tags: #{tags}\n")
f.write("---\n")
f.write(content)
end
end
# Just checks for images and reports them.
# I intend to copy/paste my wp-content/uploads dir entirely to 'public'.
require 'rubygems'
require 'nokogiri'
Dir.glob("/Users/ariejan/dev/ariejannet/articles/*.txt").each do |art|
doc = Nokogiri::HTML(open(art))
puts "Processing: #{art}"
doc.css("img").each do |img|
src = img["src"]
puts " -- #{src}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment