#!/usr/bin/python #---------------------------------------------------- # Licensed under WTFPL v2 # (see COPYING for full license text) # #---------------------------------------------------- # only works if useragent contains libcurl #---------------------------------------------------- '''[cat |] %prog [file1 file2 ...]''' __version__ = '0.3' __desc__ = ''' Upload file to paste.xinu.at and copy URL to clipboard or nopaste stdin ''' from optparse import OptionParser from subprocess import Popen, PIPE from os import isatty import sys def do_upload(file): url = Popen(['curl', '-#', '-L', '-F', 'userfile=@'+file, 'http://paste.xinu.at/file/do_upload' ], stdout=PIPE).communicate()[0] print url Popen('echo -n "%s" | nohup &>/dev/null xclip' % url, shell=True) def main(): p = OptionParser(version=__version__, usage=__doc__, description=__desc__) options, args = p.parse_args() if args: for file in args: do_upload(file) else: if isatty(sys.stdin.fileno()): print '^C to exit, ^D to send' try: content = sys.stdin.read() except KeyboardInterrupt: sys.exit() if not content: sys.exit() tmpfile = Popen('mktemp', stdout=PIPE).communicate()[0] f = open(tmpfile, 'w') f.write(content) f.close() do_upload(tmpfile) if __name__ == '__main__': main()