All pastes #449155 Raw Edit

Stuff

public ruby v1 · immutable
·published 2007-04-20 02:01 UTC
rendered paste body
#!/usr/bin/ruby -W0## This is a CLI interface to pastebin.ca# $Revision:$#require 'mechanize'require 'optparse'# set up all the options stuffoptions = {}opts = OptionParser.new do |opts|	opts.banner =  "Usage: pastie.rb [options] 			Examples: pastie.rb -f foo.rb			          cat index.html | pastie.rb -t html"	opts.separator ""	opts.separator "Options:"	opts.on("-f <file>", "--file <file>", Array,	  	"Use a file for input instead of STDIN") do |f|	        	options[:file] = f	end	syntax_hash = { "c" => "c",			"diff" => "diff",			"html" => "html",			"javascript" => "javascript",			"nitro xml" => "nitro_xml",			"pascal" => "pascal",			"plaintext" => "plain text",			"rhtml" => "rhtml",			"ruby" => "ruby",			"sql" => "sql"	}	code_list = syntax_hash.keys.sort.join(", ")	opts.on("-t", "--type <syntax type>", syntax_hash, "Syntax types can be abbriviated, as long as they are unambigous. Defaults to 'ruby'",		"  #{code_list}") do |encoding|			options[:syntax] = encoding 	end	opts.on_tail("-h", "--help", "Show this message") do	   puts opts           exit	end	opts.on_tail("--version", "Show version") do		VERSION = "$Revision:$"		puts VERSION		exit	endend# parse optionsopts.parse(ARGV)# get page and create the form objectagent = WWW::Mechanize.newagent.user_agent_alias = 'Mac Safari'page = agent.get("http://pastie.caboo.se")form = page.forms[1]# use options to fill in formif options[:file] == ""	form['paste[body]'] = $stdin.readelse	form['paste[body]'] = `cat #{options[:file]}`endif options.has_key?(:syntax)	form['paste[parser]'] = options[:syntax]end# submit results and show linksearch_results = agent.submit(form)#puts search_results.body[/http:\/\/www.pastebin.ca\/\d+/]