Skip to content

Instantly share code, notes, and snippets.

@billie66
Last active August 29, 2015 14:08
Show Gist options
  • Save billie66/5ce193c8bd2d81fd2b8f to your computer and use it in GitHub Desktop.
Save billie66/5ce193c8bd2d81fd2b8f to your computer and use it in GitHub Desktop.
get the notes of every episode from the episodes table
# encoding: UTF-8
namespace :db do
desc "get all of the notes from episodes table"
task :episodes => :environment do
def header(name)
str = <<-EOF.gsub(/^\s{6}/, '')
---
layout: post
title: #{name}
---
EOF
end
root = File.expand_path(File.dirname(__FILE__))
dir = File.join(root, 'notes')
system("mkdir #{dir}")
Episode.all.each do |e|
next if [105, 104, 103].include? e.id
prefix = case e.id
when 1..9
'00'
when 10..99
'0'
else
''
end
file = prefix + e.id.to_s + '-' + e.name + '.md'
if e.notes.empty?
notes = ''
else
notes = e.notes.gsub(/^```.*?$/, '~~~').
gsub(/(^~~~$)\n(^~~~$)/, "\\1\n\n\\2").
gsub(/\r\n?/, "\n").chomp + "\n\n"
end
File.open("#{dir}/#{file}", 'w+') do |f|
f.write(header(e.name) + notes)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment