Skip to content

Instantly share code, notes, and snippets.

@kimihito
Last active December 9, 2015 19:48
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimihito/4319131 to your computer and use it in GitHub Desktop.
Save kimihito/4319131 to your computer and use it in GitHub Desktop.
post text to tumblr on terminal.
task :default => :new
desc "Create a new article."
task :new do
title = ask("Title: ")
article = "<pre><code class=\"prettyprint lang-ruby\">
</code></pre>"
path = "./#{title}.txt"
unless File.exist? path
File.open(path, "w") do |file|
file.write article
end
puts "an article was created for you at #{path}."
system("vim", path)
else
puts "I can't create the article, #{path} already exists."
end
end
desc "Publish my blog."
task :publish do
puts "publishing your article(s)..."
`ruby termblr.rb`
puts "Posted!!"
end
def ask(message)
print message
STDIN.gets.chomp
end
#!/usr/bin/env ruby
#-*- coding: utf-8 -*-
require 'tumblr_client'
Tumblr.configure do |config|
config.consumer_key = "YOUR_CONSUMER_KEY"
config.consumer_secret = "YOUR_CONSUMER_SECRET"
config.oauth_token = "YOUR_ACCESS_TOKEN"
config.oauth_token_secret = "YOUR_TOKEN_SECRET"
end
client = Tumblr.new
blog_url = "YOUR_TOUMBLR_URL"
Dir::glob("./*.txt").each { |f|
title = File.basename(f,".txt")
content = File.read(f)
#post text queue
client.text(blog_url, :state => "queue", :title => title, :body => content)
system("rm","-f",f,f + "~")
puts "delete #{f}"
}
puts "Posted!!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment