Skip to content

Instantly share code, notes, and snippets.

@alex-ross
Created December 23, 2013 13:31
Show Gist options
  • Select an option

  • Save alex-ross/8097177 to your computer and use it in GitHub Desktop.

Select an option

Save alex-ross/8097177 to your computer and use it in GitHub Desktop.
# Converts exported json data to GH markdown pages for webbradion.net
# Must be runned from projects root directory and expects an file called 'e.json' to exists.
# e.json should be an JSON export of Episodes from Webbradions database.
require 'json'
require 'ostruct'
def content(e)
<<-EOF
---
layout: episode
permalink: /avsnitt/#{e.id}
title: #{e.title.gsub(':', ' ')}
description: #{e.description.gsub(':', ' ')}
length: #{e.length_in_minutes}
sound_file: http://webbradion.net/avsnitt/#{e.id}/download
---
#{e.shownotes.gsub('** Länkar **', '**Länkar**').gsub('** Tider **', '**Tider**')}
EOF
end
f = File.open("e.json", "r")
y = JSON.parse(f.read)
y.each do |episode|
e = OpenStruct.new(episode['episode'])
file_name = "_posts/#{e.created_at[0...10]}-avsnitt-#{e.id}.md"
File.open(file_name, 'w') { |file| file.write(content(e)) }
system('git', 'add', "#{file_name}")
system('git', 'commit', '-m', "Adds episode #{e.id}.")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment