summaryrefslogtreecommitdiffstats
path: root/fb
blob: 3016addcf6c3a07f0fbd7d43f3ac95dad9852791 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/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()