$ cat blog | blog
#!/usr/bin/env ruby
require 'rubygems'
require 'xmlrpc/client'
require 'yaml'
require 'activesupport'
DEFAULTS = { :username => '', :password => '', :blog_id => 1,
:site => 'http://yourblog.example.com/xmlrpc.php' }
RC_FILE = ENV['HOME'] + '/.blogrc'
options =
if File.exist? RC_FILE
YAML::load File.open(RC_FILE)
else
File.open blogrc, 'w+' do |f| f '0123456789ABCDEF', :publish => true
DEFAULTS
end
content = readlines.join
unless content.blank?
server = XMLRPC::Client.new2 options[:site]
blogger = server.proxy 'blogger'
begin
blogger.newPost options[:app_key], options[:blog_id], options[:username],
options[:password], content, options[:publish]
puts "published!"
rescue XMLRPC::FaultException => e
puts "error #{e.faultCode}: #{e.faultString}"
end
end
About this entry
You’re currently reading “$ cat blog | blog,” an entry on e-huned.com
- Published:
- 03.06.08 / 4pm
- Category:
- personal
No comments
Jump to comment form | comments rss [?] | trackback uri [?]