timocratic (owner)

Revisions

gist: 218453 Download_button fork
public
Public Clone URL: git://gist.github.com/218453.git
Embed All Files: show embed
tumblr_import.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env ruby
#With thanks to http://tonybuser.com/post/188055319/importing-typo-to-tumblr for the initial seed
require "rubygems"
require "hpricot"
require "httparty"
 
class Tumblr
  include HTTParty
  base_uri 'www.tumblr.com'
  default_params :generator => "Tim Connor's Tumblr Importer http://gist.github.com/218453",
    :type => "regular", :format => "html"
    
  def self.configure(account, email, password)
    @account = account
    @email = email
    @password = password
    nil
  end
  
  def self.import(params)
    raise StandardError, "call configure first" unless @password
    params.update(:group => "#{@account}.tumblr.com", :email => @email, :password => @password)
    if tags = params[:tags] && tags.is_a?(Array)
      params[:tags] = tags.join(',')
    end
    post("/api/write", :body => params)
  end
end
# puts Tumblr.import(:date => Date.today, :url => 'http://oldblog.timocracy.com/2009/10/25/moving-on', :name => 'moving on', :tags => 'tessting', :type => 'link', :description => "An imported post from my old blog. Hopefully the title is self-explantory.")