Last active
December 9, 2015 19:48
-
-
Save kimihito/4319131 to your computer and use it in GitHub Desktop.
post text to tumblr on terminal.
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
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 |
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
#!/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