dotfiles

My opinionated dotfiles
git clone git://git.erethon.com/dotfiles
Log | Files | Refs

pybin (1673B)


      1 #!/usr/bin/python
      2 # Erethon's terminal pastebin. It uses mechanize, so you don't need to have a
      3 # pastebin account/API key, but it's an overkill to use mechanize for something
      4 # simple like this.
      5 # License is the MIT license, see LICENSE and README.md files for more info.
      6 # For updates check https://erethon.com and https://github.com/erethon
      7 # Copyright (C) 2013 Erethon
      8 
      9 import sys
     10 import mechanize
     11 import argparse
     12 
     13 parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
     14 parser.add_argument('infile', nargs='?', type=argparse.FileType('r'),
     15                     default=sys.stdin)
     16 parser.add_argument('-e', '--expires', dest='expires', default='10M',
     17                     help='Time until paste expires. Accepted values:\n'
     18                     '10 minutes, 1 hour, 1 day, 1 week, 2 weeks, 1 month, '
     19                     'never \n(10M, 1H, 1D, 1W, 2W, 1M, *N)')
     20 
     21 parser.add_argument('-v', '--visibility', dest='visibility', default='1',
     22                     help='Set visibility of paste (0=public, 1=Unlisted)')
     23 
     24 parser.add_argument('-t', '--title', dest='title', default='',
     25                     help='Set title of paste')
     26 
     27 
     28 arg = parser.parse_args()
     29 
     30 with arg.infile:
     31     paste = arg.infile.read()
     32 
     33 br = mechanize.Browser()
     34 br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; Linux x86_64)'
     35                   'AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 '
     36                   'Safari/535.11')]
     37 
     38 br.open("http://pastebin.com")
     39 
     40 br.select_form(nr=1)
     41 br.form['paste_code'] = paste
     42 br.form['paste_expire_date'] = [arg.expires, ]
     43 br.form['paste_private'] = [arg.visibility, ]
     44 br.form['paste_name'] = arg.title
     45 br.submit()
     46 
     47 print br.geturl()