diff options
author | Florian Pritz <f-p@gmx.at> | 2009-07-13 18:59:32 +0200 |
---|---|---|
committer | Florian Pritz <f-p@gmx.at> | 2009-07-13 18:59:32 +0200 |
commit | 2505049059cd5321f2f48434b354969524b02afb (patch) | |
tree | 7865d2c09e8fb08b509822da64a5667eedda7d3a /fb | |
parent | 2572c8d2d1b8d804af53d6a772c1b358751a86ad (diff) | |
download | bin-2505049059cd5321f2f48434b354969524b02afb.tar.gz bin-2505049059cd5321f2f48434b354969524b02afb.tar.xz |
rewrite fb in python
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() |