No line Numbers New Paste http://endtable.net/paste/ln0a6560b7.html Link to this paste
#!/usr/bin/python

usage = """Syntax: paste [ -h|--help ] [ -d|--delay <integer> ] [ --no-delay ] [ -i|--irc <IRC channel> ] [ -n|--nick <IRC handle> ]

Author: Michal Guerquin
August 2005

Read stdin, wait delay seconds (default
is 5), upload to http://endtable.net/paste/
and show the resulting URL.

Example usage: cat /etc/passwd | paste.py

"""

changes = """

Changes:

2006-11-06
- Added getopt option parsing (kolbe)

"""

import urllib, urllib2, sys, time, getopt, os

# default arguments
delay = 5
irc_channel = ""
language = "txt"
nick = os.getenv("USER") or "some UNIX addict"
verbose = 0

try:
        opts, args = getopt.getopt(sys.argv[1:], "hvi:d:l:n:", ["help", "irc=", "delay=","no-delay","language","nick="])
except getopt.GetoptError:
  sys.exit(usage)

for o, a in opts:
  if o in ("-h", "--help"):
    sys.exit(usage)
  if o in ("-i", "--irc"):
    irc_channel = a
  if o in ("-d", "--delay"):
    try:
      delay = int(a)
    except:
      sys.stderr.write("Invalid argument for -d/--delay\n")
      sys.exit(usage)
  if o == "--no-delay":
    delay = 0
  if o in ("-l","--language"):
    language = a
  if o == "-v":
    verbose = 1
  if o in ("-n","--nick"):
    nick = a

# prepend hash to IRC channel name if not already present
if irc_channel and not irc_channel.startswith("#"):
  irc_channel = "#" + irc_channel


if verbose:
  print >> sys.stderr, "IRC Channel: ", irc_channel
  print >> sys.stderr, "Delay: ", delay
  print >> sys.stderr, "Language: ", language


# read data
rawdata = "".join(sys.stdin.readlines())

# write info
print "Will paste",len(rawdata),"bytes of data"


# prepare data
data = urllib.urlencode(dict(paste=rawdata, language=language, channel=irc_channel, nick=nick, theme="typical", nummer=36))

#nummer is miles' hardcoded captcha, probably subject to change

#("User-Agent","mikeg's nerdpics script")

# show timer
if delay:
  print delay,
  sys.stdout.flush()
  for i in range(delay-1,-1,-1):
    time.sleep(1)
    print i,
    sys.stdout.flush()
  print

# paste it
print "Pasting..."

req = urllib2.Request("http://endtable.net/paste/", data=data, headers={"User-Agent": "mikeg's paste script"})
u = urllib2.urlopen(req)

# show resulting URL
print "URL:", u.geturl()