3 # Purpose: paste files to the online grml paste bot
4 # Authors: grml-team (grml.org), (c) 2007 Nico Golde <nico@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2
7 ##########################################################################
12 url = URI.parse('http://paste.grml.org/paste')
15 $stderr.puts "usage: #{$0} [-n nick] [-s summary] [-f source] [-h|--help]\n"
16 $stderr.puts "\t -n <nick>\tset your nickname (defaults to Anonymuos)"
17 $stderr.puts "\t -s <summary>\tspecify a summary of your paste (defaults to none)"
18 $stderr.puts "\t -f <source>\tsets the file to read from, you don't need this for reading from stdin"
19 $stderr.puts "\t --help\t\tprint this help"
29 ARGV.each_index do |i|
30 if ARGV[i] == '-h' or ARGV[i] == '--help' then
32 elsif ARGV[i] == '-n' and ARGV[i+1] != nil then
34 elsif ARGV[i] == '-s' and ARGV[i+1] != nil then
36 elsif ARGV[i] == '-f' and ARGV[i+1] != nil then
41 if file == nil or file == "-"
47 $stderr.puts "Error: couldn't open file: #{file}"
57 res = Net::HTTP.post_form(url,{'Paste it' => 'Paste it', 'paste' => text, 'channel' => channel, 'summary' => summary, 'nick' => nick})
59 $stderr.puts "Unable to post HTTP request"
63 results = res.body.scan(/<a href='http:\/\/paste.grml.org\/[0-9]+'/)
65 if results.size > 0 then
66 result = results[0].sub(/<a href='(http:\/\/paste.grml.org\/[0-9]+)'/, '\1')
70 print "Failed to paste, please retry\n"
72 print "You can find your paste on: " + result + "\n"
75 ## END OF FILE #################################################################