diff options
Diffstat (limited to 'fb')
-rwxr-xr-x | fb | 69 |
1 files changed, 46 insertions, 23 deletions
@@ -1,32 +1,55 @@ -#!/bin/sh +#!/usr/bin/python #---------------------------------------------------- -# Version: 0.2.3 -# Author: Florian "Bluewind" Pritz <f-p@gmx.at> -# # Licensed under WTFPL v2 # (see COPYING for full license text) # #---------------------------------------------------- -# Upload file to my filebin and copy URL to clipboard -# or nopaste stdin -# (only works if useragent contains libcurl) +# only works if useragent contains libcurl #---------------------------------------------------- -tmpfile=0 -if [ -n "$1" ]; then - file=$1 -else - file=$(mktemp) - tmpfile=1 - while read -r input; do - echo "$input" >> $file - done -fi +'''[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() -URL=$(curl -# -L -F "userfile=@$file" http://paste.xinu.at/file/do_upload) -echo $URL -echo -n $URL | nohup &> /dev/null xclip + 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 [ "$tmpfile" == "1" ]; then - rm $file -fi +if __name__ == '__main__': + main() |