usr bin env python import os import sys import urllib import urllib2 U

 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
56
57
58
59
60
#!/usr/bin/env python
import os
import sys
import urllib
import urllib2
URL = 'http://dumpz.org/'
if len(sys.argv) < 2:
sys.exit("Not enough parameters.")
elif len(sys.argv) > 2:
sys.exit("Too many parameters.")
fname = sys.argv[-1]
if os.path.exists(fname):
fcont = open(fname,'r').read()
ext = fname.split('/')[-1].split('.')[-1]
highlighting = 'text'
if ext == 'sh':
highlighting = 'bash'
elif ext == 'hs':
highlighting = 'haskell'
elif ext in ['c', 'h']:
highlighting = 'c'
elif ext in ['cpp', 'hpp']:
highlighting = 'cpp'
elif ext in ['html','htm']:
highlighting = 'html'
elif ext == 'php':
highlighting = 'php'
elif ext == 'py':
highlighting = 'python'
elif ext == 'css':
highlighting = 'css'
elif ext == 'sql':
highlighting = 'sql'
values = { 'lexer': highlighting,
'code': fcont,
}
data = urllib.urlencode(values)
req = urllib2.Request(URL ,data,
{'Content-type':'application/x-www-form-urlencoded'})
res = urllib2.urlopen(req)
url = res.url
print "Pasted at %s" % url
print "Trying to add to clipboard using xclip.."
os.system('echo -n "%s" | xclip' % url)
else:
sys.exit("File not found: %s" % fname)