Skip to content

Instantly share code, notes, and snippets.

@cloudhead
Created February 18, 2010 22:08
Show Gist options
  • Save cloudhead/308128 to your computer and use it in GitHub Desktop.
Save cloudhead/308128 to your computer and use it in GitHub Desktop.
script used to import usabilitypost.com posts from wp to toto
i = 0
File.read("wp_posts2.csv").split('$$')[1..-1].each do |entry|
next if entry.gsub(/\n/,'').empty?
print '.'
date, body, title, slug = entry.split('||').map {|e| e.sub(/^""/, '').sub(/""$/, '') }
puts title if title.include? ':'
slug = title.downcase.gsub('[^a-z0-9]+', '-') if slug.empty?
date = date.split(/ +/).first
File.open("articles/#{date}-#{slug}.txt", "w") do |file|
file.write("title: #{title}\ndate: #{date.gsub('-', '/')}\nslug: #{slug}\n\n#{body}\n")
i += 1
end
end
puts
puts "#{i} articles imported"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment