I know there are plenty. I know they can do much. But I like to roll my own minimalistic solutions.
It can read from files, stdin (until an EOL is issued) and
soon maybe the clipboard.
Pretty easy to use, you just need a pastebin API key (more info
here), a terminal on some
Unix and something to paste.
EDIT: Of course you'll need requests, too.
To install,
$ sudo pip install requests
EDIT2:
To use the optional clipboard dependency, run
$ sudo pip install clipboard
(I might write my own tho, if someone wants).
(Or just download and install from
pypi).
EDIT: cleaned and updated the code a bit.
EDIT3: Incorporated kenjoe41's suggestions. Thank you.
Here's the code:
import argparse
import sys
import requests
HAS_CLIPBOARD = True
try:
import clipboard
except ImportError:
HAS_CLIPBOARD = False
def post(string, form, expiry):
post_dict = {'api_dev_key': '51652104665c18834023dae5d21d2a56',
'api_option': 'paste',
'api_paste_code': string
}
if form:
post_dict['api_paste_format'] = form
if expiry:
post_dict['api_paste_expiry_date'] = expiry
return requests.post('http://www.pastebin.com/api/api_post.php', post_dict)
def get_input(source):
if source != 'stdin':
with open(source, 'r') as f:
return f.read()
return sys.stdin.read()
if __name__ == '__main__':
ARG_PARSER = argparse.ArgumentParser(
description='Post something to pastebin.com')
ARG_PARSER.add_argument('-s', default='stdin',
help='The source of the paste (default: stdin).')
ARG_PARSER.add_argument('-f', help='The format (default: none.')
ARG_PARSER.add_argument('-e', help='The expiry time (default:none).')
ARG_PARSER.add_argument('-c', help='Use clipboard as source',
action='store_true')
ARGS = ARG_PARSER.parse_args()
if not ARGS.c:
input_string = get_input(ARGS.s)
elif HAS_CLIPBOARD:
input_string = clipboard.paste()
else:
print 'You don\'t have https://pypi.python.org/pypi/clipboard!'
sys.exit()
print '\nuploading...'
print post(input_string, ARGS.f, ARGS.e).content