Created
October 30, 2009 04:16
-
-
Save cdmoyer/222114 to your computer and use it in GitHub Desktop.
Script to import bloxsom blog to tumblr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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