--- ../fpaste-0.3.7.1.orig/fpaste 2013-04-17 23:26:12.821180847 +1000
+++ fpaste 2013-04-17 23:24:46.127666845 +1000
@@ -64,6 +64,18 @@
else:
return False
+def get_shortened_url(long_url):
+ """Get shortened URL from paste data"""
+ req = urllib2.Request(url=long_url+'/', data='mode=json')
+ try:
+ f = urllib2.urlopen(req)
+ except urllib2.URLError:
+ return False
+
+ for line in f.readlines():
+ if 'short_url' in line:
+ return json.loads('{' + line +'}')['short_url']
+
def paste(text, options):
'''send text to fpaste.org and return the URL'''
@@ -121,7 +133,12 @@
url = "{0}{1}/{2}".format(options.url, id, private_hash)
else:
url = "{0}{1}".format(options.url, id)
- return url
+
+ short_url = get_shortened_url(url)
+ if short_url:
+ return [url, short_url]
+ else:
+ return [url, url]
# url = f.geturl()
# if re.match(FPASTE_URL + '?.+', url):
@@ -394,7 +411,7 @@
if not confirm("OK to send?"):
sys.exit(1)
- url = paste(text, options)
+ [url, short_url] = paste(text, options)
if url:
# try to save URL in clipboard, and warn but don't error
if options.clipout:
@@ -408,7 +425,11 @@
#parser.error("'xsel' failure. this usually means you're not running X")
print >> sys.stderr, "WARNING: URL not saved to clipboard"
- print url
+ if url == short_url:
+ print url
+ else:
+ print short_url + " -> " + url
+
else:
sys.exit(1)