Skip to content

Instantly share code, notes, and snippets.

@cdmoyer
Created October 30, 2009 04:16
Show Gist options
  • Save cdmoyer/222114 to your computer and use it in GitHub Desktop.
Save cdmoyer/222114 to your computer and use it in GitHub Desktop.
Script to import bloxsom blog to tumblr
require 'rubygems'
require 'redcloth'
require 'net/http'
require 'uri'
user = 'your@email.here'
pass = 'thisisnotit'
url = URI.parse('http://www.tumblr.com/api/write')
ARGF.each do |f|
f.strip!
dt = `ls -lh --time-style=long-iso #{f}`
dt.sub!(/.* 200/, '200')
dt.sub!(/( .*) .*/, '\1')
title = nil
tags = nil
body = ''
File.open(f).each do |l|
if not title then title = l
elsif !tags and l.match(/^tags:/i) then
tags = l.sub(/^tags:\s*/i,'').split(/,/).map {|s|s.strip.gsub(/_/,' ')}
else
body += l
end
end
body.sub(/^\s*/, '')
body = RedCloth.new(body).to_html
# title, body, dt, tags
res = Net::HTTP.post_form(url,
{
'email' => user,
'password' => pass,
'type' => 'regular',
'generator' => 'CDMoyer\'s Custom Importer',
'date' => dt,
'tags' => tags ? tags.map {|s| "\"#{s}\""} .join(',') : "",
'format' => 'html',
'title' => title,
'body' => body
}
)
puts res.body
sleep(5)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment